Congratulations, you’ve just created a new Play application!
Play Framework makes it easy to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on Akka, Play provides predictable and minimal resource consumption for highly-scalable applications.
This tutorial introduces you to the essentials of your new Play application.
Before we go any further, let's run the application.
In Play, web requests are handled by Action
s.
Action
s process each request, perform any work that's needed, and then return a Result
. Action
s are generated by Controller
s.
This application defines a Controller
in app/controllers/HomeController.scala. HomeController
's index
method creates an Action
which returns a Result
of Ok
.
Learn about Actions, Controllers and Results
Play routes incoming HTTP requests to their Action
s. The mappings between requests and Action
s are defined in conf/routes.
This application renders HTML using Twirl templates.
The templates are defined in the app/views directory. Each Twirl template is compiled into a Scala object which can be called from Java or Scala code.
The views.html.index(...)
code within HomeController.scala calls the app/views/index.scala.html template.
Twirl ships with Play by default but you can use other view technologies too. For example, you could use Handlebars instead of Twirl.
Your application automatically serves static resources such as JavaScript, CSS and images.
Normal assets live in the public folder.
Assets that need compilation, such as CoffeeScript and LESS files, go in the app/assets folder. These assets have extra processing applied to them.
Assets are served by Play's Assets
controller. The Assets
controller is configured in the conf/routes file.
Learn about Working with Assets
Your Play application is built with sbt.
Build configuration is defined in the build.sbt file. You can edit this file to add new project dependencies or to change compilation settings.
Plugins extend sbt with new behavior. You can set up sbt plugins in the project/plugins.sbt file. The Play sbt plugin is configured in this file. There are also separate plugins to compile assets, such as CoffeeScript and LESS.
You can change your application's runtime behavior by editing conf/application.conf file. There are lots of commented-out settings in there for you to use as a starting point.
Play uses the Typesafe Config Library to manage its configuration. Editing the application.conf
file is just one of many ways that you can configure your application.
You're probably reading this tutorial right now from within Typesafe Activator's browser UI. However, if you prefer, you can build and run your application from the command line.
$ activator ~run
You can run tests from the command line too.
$ activator ~test
General information about Play is available from playframework.com.
There is documentation available online.
You can also ask questions on Stack Overflow.