Tutorial #1:Getting started with Play Framework


In this blog we would set up the development environment with Play and Eclipse which would drive us through rest of the tutorial series.  We would be running this blog as a series and we would be looking at various aspects of play with this blog.

In this tutorial we will discuss about the following topics of Play Framework:

  • Installing Play
  • New application
  • Layout of Play application
  • Play console
  • Setting-up Eclipse

∗ Installing Play

Prerequisites: To run the Play framework, you need JDK 6 or later

Step-1: Download Activator from here

Step-2: Go to the ZIP file path and UNZIP it

anand@anand-singh:~$ cd softwares/
anand@anand-singh:~/softwares$ unzip typesafe-activator-1.2.10-minimal.zip
Archive:  typesafe-activator-1.2.10-minimal.zip
   creating: activator-1.2.10-minimal/
  inflating: activator-1.2.10-minimal/activator.bat  
  inflating: activator-1.2.10-minimal/activator  
  inflating: activator-1.2.10-minimal/activator-launch-1.2.10.jar  

Step-3: Set the activator to your path

anand@anand-singh:~$ vi .bashrc
export TYPESAFE_ACTIVATOR=/home/anand/softwares/activator-1.2.10-minimal

To check
anand@anand-singh:~$ which activator

Step-4: Check the activator command

anand@anand-singh:~$ activator -help


Now your system is ready to create a new Play application.

NOTE: If you don’t want to setup the activator into your path then just unzip and go to the activator script path and use it.

anand@anand-singh:~$ cd softwares/activator-1.2.10-minimal/
anand@anand-singh:~/softwares/activator-1.2.10-minimal$ ./activator -help

The result of "./activator -help" command is same like above screen.

∗ New application

There are several way to create new application using activator command:

$ activator new play-scala-tutorial-one play-scala


$ activator new play-scala-tutorial-one


∗ Layout of Play application

app                       Application sources
  assets                 Compiled asset sources
     stylesheets         Typically LESS CSS sources
     javascripts         Typically CoffeeScript sources
  controllers            Application controllers
  models                 Application business layer
  views                  Templates
build.sbt                 Application build script
conf                      Configurations files
  application.conf       Main configuration file
  routes                 Routes definition
public                    Public assets
  stylesheets            CSS files
  javascripts            Javascript files
  images                 Image files
project                   sbt configuration files
  build.properties       Marker for sbt project
  plugins.sbt            sbt plugins including play declaration
lib                       Unmanaged libraries dependencies
logs                      Standard logs folder
  application.log        Default log file
target                    Generated stuff
     classes             Compiled class files
     classes_managed     Managed class files (templates, ...)
     resource_managed    Managed resources (less, ...)
     src_managed         Generated sources (templates, ...)
test                      source folder for unit or functional tests

∗ Play Console

$ cd play-scala-tutorial-one
$ activator
[info] Loading project definition from /home/anand/projects/knoldus/play-scala-tutorial-one/project
[info] Set current project to play-scala-tutorial-one (in build file:/home/anand/projects/knoldus/play-scala-tutorial-one/)
[play-scala-tutorial-one] $ 

To Help:
[play-scala-tutorial-one] $ help run
Runs a main class, passing along arguments provided on the command line.
[play-scala-tutorial-one] $ help compile
Compiles sources.
[play-scala-tutorial-one] $ 

To Compile:
[play-scala-tutorial-one] $ compile
[success] Total time: 0 s, completed 3 Oct, 2014 12:11:34 PM
[play-scala-tutorial-one] $

The Play console is just a normal sbt console, so you can use sbt features such as triggered execution.

For example, using ~ compile

[play-scala-tutorial-one] $ ~ compile

The compilation will be triggered each time you change a source file.

If you are using ~ run

[play-scala-tutorial-one] $ ~ run

The triggered compilation will be enabled while a development server is running.

You can also do the same for ~ test, to continuously test your project each time you modify a source file:

[play-scala-tutorial-one] $ ~ test


∗ Setting-up Eclipse

[play-scala-tutorial-one] $ eclipse

Import the application into your Workspace with the File/Import/General/Existing project… menu (compile your project first).


This is the start of tutorial series, from next week onwards we would be working on this tutorial blog to make it grow. We would look at how we can make it more usable and readable, then we would be adding next tutorial of “Using Bootstrap, Bootswatch and WebJars with Play application”. If you have any question then feel free to comment on the same 🙂 Stay tuned.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s