Wednesday, August 20, 2014

How To Create Distributable Staging Build In Play

Play is one of the easiest and fastest frameworks to create Java and Scala based web applications.  Usually in J2EE applications deploying the web applications require application server and web server on which builds can be deployed.  Play is different.

You do not need any application server or web server.  You just need JRE in your system.  If you are able to run java and javac commands on the command prompt you should be able to run any play application. Isn't that wonderful?

One unique thing about Play build is for production you would need Unix or Linux environment.  The reason behind this is Play would need a separate process to run on.  That is truly possible on Unix and not Windows.  In Windows you can create a staging build.  Fortunately the process is similar for both Production and Staging as far as creating the build is concerned.  In this article I will show you how to create a Stage build for Windows environment.

How To Create Distributable Staging Build In Play (Ver 2.2.3)

Here are the steps to create staging build on Windows.  With help from (

  1. Ensure that the Play application you have created runs on local Netty server.  Running it is very simple.  Just issue the command Play run on command prompt.  Then you should be able to access the application on browser at http://localhost:9000/  
  2. Ensure that JAVA_HOME is set to bin directory where java.exe and javac.exe are present on your computer.  For example in my machine JAVA_HOME is set as C:\Program Files (x86)\IBM\SDP80\jdk\bin
  3. Now go to command prompt and browse to the play application folder.
  4. Issue the command - Play clean stage
  5. This will create a directory [application-workspace]\target\universal\stage\bin
  6. You will find a file called [your_app].bat.  For example if the app name is helloWorld the file will be called helloWorld.bat.
  7. Create a folder dist in the [application-workspace] folder.
  8. Copy the bat file in step 5 to the dist folder.  The reason is next time automatically this file will be copied from the dist directory to the target folder.
  9. Edit the bat file in any text editor.
  10. Change the following line 
       if "%HELLOWORLD_HOME%"=="" set "HELLOWORLD_HOME=%~dp0\\.."
       if "%HELLOWORLD_HOME%"=="" set "HELLOWORLD_HOME=%~dp0\\"

Basically remove the last two dots (..) at the end of the line.  In my example the application name is helloWorld.  If your application name is different then you will see [application_name]_HOME as appropriate.
10. Search for the line which starts with set "APP_CLASSPATH=
11. It will have the names of all jar files required in the application....
set "APP_CLASSPATH=%APP_LIB_DIR%\helloworld.helloworld-1.0-SNAPSHOT.jar;%APP_LIB_DIR%\....
   Change this line to

set "APP_CLASSPATH=%APP_LIB_DIR%\helloworld.helloworld-1.0-SNAPSHOT.jar;%APP_LIB_DIR%\*"

Adding the asterisk at the end will ensure that all jar files are included in the class path.
12. Save the bat file and close it.
13. Now copy it back to [application-workspace]\target\universal\stage\bin 
14.  To test it go to [application-workspace]\target\universal\stage\bin and run the bat file.  You should see the something similar to
     Play server process ID is 14180
     [info] play - Application started (Prod)
     [info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
15. Now your application is ready to test.  You can access it on http://localhost:9000 in your browser.
16. Now you can zip your stage directory and distribute to other machines where JRE is available and run it on that machine.

Related Article 

How to Deploy Play Application on Tomcat

No comments:

Post a Comment