Monday, May 15, 2017

Play framework getting started with activator

The earlier post introduces to Play, sbt and activator versions and the differences in the installation procedures.
This post describes the Play installation procedures with the activator. The procedure is relevant for the sbt version before 0.13.13.

Installation

Download and install:
1. Java 8 - download the relevant installation from Oracle site.
2. sbt - download from www.scala-sbt.org version.
3. activator - download zip from www.lightbend.com/activator/download and extract files to the target Play folder, for example to:
C:\Play-2.4.2\activator-dist-1.3.5
Define the environment variables:
1. JAVA_HOME, for example:
C:\Program Files\Java\jdk1.8.0_45
2. PLAY_HOME, for example:
C:\Play-2.4.2\activator-dist-1.3.5;
3. SBT_HOME for example:
C:\Program Files (x86)\sbt;  
Add path to all three installed programs to the path variables:
%JAVA_HOME%\bin;%PLAY_HOME%\bin;%SBT_HOME%\bin;

Play 2.5.3 installation fix

Installation of Play 2.5.3 (the last 2.5 stable release) comes with a minor problem.
To fix it:
1. Edit the file activator-dist-1.3.10\bin\activator.bat and add the "%" character at the end of line 55. The proper line should be like this:
set SBT_HOME=%BIN_DIRECTORY%
2. Create sub-directory conf under the activator root directory activator-dist-1.3.10.
3. Create in the conf directory an empty file named sbtconfig.txt.

Creating a new application

Start the cmd from the directory, where a new application should be created.
The shortest way to create a new application via CLI is to provide an application name and template as CLI arguments:
activator new my-play-app play-java
It is possible to run just:
activator new
In this case you will be prompted to select the desired template and an application name.

For Play 2.4 add manually to project/plugins.sbt:
// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.x")
Be sure to replace 2.4.x here by the exact version you want to use.
Play 2.5 generates this line automatically.

Make sure that the proper sbt version is used in project/build.properties. It should match to sbt version, installed on your machine. For example:
sbt.version=0.13.8
That's it, a new application now may be started:
cd my-play-app
activator run
After a while the server will start and the following prompt should appear on the console:
 [info] p.c.s.NettyServer - 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...)
The server by default is listening on port 9000. You can request it from a browser by the URL http://localhost:9000. You will get something like this:


Running activator on a different port

By default the activator runs an application on port 9000 for http or 443 for https.
To run an application on the different port (http):
activator "run 9005"

Going further


Import the project to eclipse with the post eclipse IDE setting
Convert the project to maven with the post creating of maven project

No comments :

About the author

My Photo
I trust only simple code and believe that code should be handsome. This is not a matter of technology, but professional approach, consolidated after years of software development. I enjoy to cause things working and feel very happy, when I manage to solve a problem.
Back to Top