Typesafe Activator

Play Scala Seed

Play Scala Seed

November 18, 2015
playframework scala seed

Seed for starting a new Play Scala project

How to get "Play Scala Seed" on your computer

There are several ways to get this template.

Option 1: Choose play-scala in the Typesafe Activator UI.

Already have Typesafe Activator (get it here)? Launch the UI then search for play-scala in the list of templates.

Option 2: Download the play-scala project as a zip archive

If you haven't installed Activator, you can get the code by downloading the template bundle for play-scala.

  1. Download the Template Bundle for "Play Scala Seed"
  2. Extract the downloaded zip file to your system
  3. The bundle includes a small bootstrap script that can start Activator. To start Typesafe Activator's UI:

    In your File Explorer, navigate into the directory that the template was extracted to, right-click on the file named "activator.bat", then select "Open", and if prompted with a warning, click to continue:

    Or from a command line:

     C:\Users\typesafe\play-scala> activator ui 
    This will start Typesafe Activator and open this template in your browser.

Option 3: Create a play-scala project from the command line

If you have Typesafe Activator, use its command line mode to create a new project from this template. Type activator new PROJECTNAME play-scala on the command line.

Option 4: View the template source

The creator of this template maintains it at https://github.com/playframework/playframework/tree/master/templates/play-scala.

Option 5: Preview the tutorial below

We've included the text of this template's tutorial below, but it may work better if you view it inside Activator on your computer. Activator tutorials are often designed to be interactive.

Preview the tutorial

Welcome to Play 2.4.4

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.

Run Your Application

Before we go any further, let's run the application.

  1. Go to the Run page.
  2. Click Run to start the application (if needed).
  3. View the running application at http://localhost:9000.

Actions, Controllers and Results

In Play, web requests are handled by Actions.

Actions process each request, perform any work that's needed, and then return a Result. Actions are generated by Controllers.

This application defines a Controller in app/controllers/Application.scala. Application's index method creates an Action which returns a Result of Ok.

Learn about Actions, Controllers and Results

HTTP Routing

Play routes incoming HTTP requests to their Actions. The mappings between requests and Actions are defined in conf/routes.

Learn about HTTP Routing

Twirl Templates

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 Application.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.

Learn about Twirl Templates

Static Assets

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

Build System

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.

Learn about the Build System

Runtime Configuration

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.

Learn about Configuration

Command Line

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

Learn about the Play console

More Information

General information about Play is available from playframework.com.

There is documentation available online.

You can also ask questions on Stack Overflow.

comments powered by Disqus