Play is based on a lightweight, stateless, web-friendly architecture.
Built on Akka, Play provides predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications.
Low boilerplating, single lines to achieve results
Code change, reload and see result, instead of long
Build deploy cycles
Developer productivity
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@knoldus:~/software$ unzip typesafe-activator-1.2.12-minimal.zip
Archive: typesafe-activator-1.2.12-minimal.zip
creating: activator-1.2.12-minimal/
inflating: activator-1.2.12-minimal/activator.bat
inflating: activator-1.2.12-minimal/activator
inflating: activator-1.2.12-minimal/activator-launch-1.2.12.jar
anand@knoldus:~/software$
Step-3: Set the activator to your path
anand@knoldus:~$ vi .bashrc
export TYPESAFE_ACTIVATOR=/home/anand/software/activator-1.2.10-minimal
export PATH=$PATH:$TYPESAFE_ACTIVATOR
To check
anand@knoldus:~$ which activator
/home/anand/software/activator-1.2.10-minimal/activator
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.
Step-4: Check the activator command
Now your system is ready to create a new Play application.
anand@knoldus:~$ activator -help
Usage: activator <command> [options]
Command:
ui Start the Activator UI
new [name] [template-id] Create a new project with [name] using template [template-id]
list-templates Print all available template names
-h | -help Print this message
Options:
-v | -verbose Make this runner chattier
-d | -debug Set sbt log level to debug
-mem <integer> Set memory options (default: , which is -Xms1024m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=256m)
-jvm-debug <port> Turn on JVM debugging, open at the given port.
# java version (default: java from PATH, currently java version "1.7.0_72")
-java-home <path> Alternate JAVA_HOME
# jvm options and output control
-Dkey=val Pass -Dkey=val directly to the java runtime
-J-X Pass option -X directly to the java runtime
(-J is stripped)
# environment variables (read from context)
JAVA_OPTS Environment variable, if unset uses ""
SBT_OPTS Environment variable, if unset uses ""
ACTIVATOR_OPTS Environment variable, if unset uses ""
In the case of duplicated or conflicting options, the order above
shows precedence: environment variables lowest, command line options highest.
anand@knoldus:~/projects/examples$ activator new into-to-play play-scala
Fetching the latest list of templates...
OK, application "into-to-play" is being created using the "play-scala" template.
To run "into-to-play" from the command line, "cd into-to-play" then:
/home/anand/projects/examples/into-to-play/activator run
To run the test for "into-to-play" from the command line, "cd into-to-play" then:
/home/anand/projects/examples/into-to-play/activator test
To run the Activator UI for "into-to-play" from the command line, "cd into-to-play" then:
/home/anand/projects/examples/into-to-play/activator ui
anand@knoldus:~/projects/examples$
$ activator new into-to-play play-scala
app — Application source code
conf — Configuration files and data
project — Project build scripts
public — Publicly accessible static files
test — Automated tests
project — sbt build definitions
target — everything generated by build system
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 and other non-compiled resources (on classpath)
└ 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 the declaration for Play itself
lib → Unmanaged libraries dependencies
logs → Standard logs folder
└ application.log → Default log file
target → Generated stuff
└ scala-2.10.0
└ cache
└ 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
HTTP Method URL Path Controller Action Mapping
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET / controllers.Application.index
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
activator : To launch play console .
run : To run current application in development mode .
compile : To compile application without running the server .
clean : To clean current application without running server.
console : To enter the interactive Scala console, which allows you to test your code interactively
help : To get basic help about the available command .
Batch Mode Command
activator clean compile run
Note : You can also use “sbt” instead of “activator” command
$ cd into-to-play
$ activator
anand@knoldus:~/projects/examples$ cd into-to-play/
anand@knoldus:~/projects/examples/into-to-play$ activator
[info] Loading project definition from /home/anand/projects/examples/into-to-play/project
[info] Updating {file:/home/anand/projects/examples/into-to-play/project/}into-to-play-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to into-to-play (in build file:/home/anand/projects/examples/into-to-play/)
[into-to-play] $
To launch the play application , change the directory of your project and run “activator”
$ run
[into-to-play] $ run
[info] Updating {file:/home/anand/projects/examples/into-to-play/}root...
[info] Resolving jline#jline;2.11 ...
[info] Done updating.
--- (Running the application, auto-reloading is enabled) ---
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
(Server started, use Ctrl+D to stop and go back to the console...)
To run the current application in development mode,
use the run command:
$ run 8080
[into-to-play] $ run 8080
--- (Running the application, auto-reloading is enabled) ---
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:8080
(Server started, use Ctrl+D to stop and go back to the console...)
Just type run to start the server on port 9000, but if that port is already taken by another application (such as Eclipse), specify a different port for it to run on:
When you see the “Server started” message, the Play server is running, and you can now access your application from a browser. Because started the server on port 8080, access the http://localhost:8080/ URL in browser and you see