Play Web Application Framework

Play Web Application Framework

Definition

Play is a Java and Scala web application framework that integrates the following components and APIs you need for modern web application development:

  • JQuery
  • Scala
  • Java
  • JavaScript
  • SBT

Installation

MySQL 

Is already installed under linux. You may install phpmyadmin for graphically supported database management.

Oracle JDK 7

Add PPA Repository and install Oracle Java 7 installer for Java SE 7 and Java FX:

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java7-installer

Setting environements variables:

$ sudo apt-get install oracle-java7-set-default

See also Ubuntu Wiki: Oracle Java, Install Oracle Java in Ubuntu via PPA 

Play Framework

Simply download SDK from here and extract the zipped archive into an arbitrary folder. For seting the corresponding environement variables put the following line to the end of the file ~/.profile.

PATH="$PATH:$HOME/DEVEL/play-2.1.0"

Cloud Bees SDK

Follow this description and don’t forget to 2 export environement variable. For seting the corresponding environement variables put the following lines to the end of the file ~/.profile and export them to vget started immediatly.

BEES_HOME=~/DEVEL/cloudbees/cloudbees-sdk-1.3.1 
PATH=$PATH:$BEES_HOME

Then at the console enter to finalize installation:

$ bees help

Adding a Cloudbees Web Application based on the Play Framework (see also: 1)

1. First of all add a ClickStart Application 4 the Play Framework and run the application on the server:
2. Set connection via SSH by following the next steps:

  1. Generate SSH-Keys: ssh-keygen -t rsa
  2. Set SSH-Keys in Cloudbees GrandCentral (See Account > Security Keys)
  3. Test SSH Connection: ssh git@git.cloudbees.com echo

2. Clone from the Git remote repository:

git clone ssh://git@git.cloudbees.com/devel/develsplay.git

3. Run the application locally:

[app] $ play run

4. For simple manually triggered Auto-Deploying / Checkin via Cloudbees SDK the Play 2 Application (see also link) wirte a bash script and put it into the root directory of your project or run those from inside your applicationsfolder. Replace APP_ID and APP_NAMEVERSION by your custom values.

#!/bin/bash
play dist
bees app:deploy -a APP_ID -t play2  dist/APP_NAME-VERSION.zip

Problem: Unsupported Configuration parameters (${MYSQL_PASSWORD_DB})

Solution 0: Set database parameters in develsplay/conf/application.conf. > Overrides on checkin (partly solution was to .gitignore).
Solution 1: Define build environement variables permanently via CloudBees SDK
First checkout out your CloudBees configuration info: 
$ bees db:info -p devels--1
Database name: devels--1 Account: devel Status: active Master: ec2-50-19-213-178.compute-1.amazonaws.com:3306 Port: 3306 Username: devels--1 Password: e00c73c055b545a2b9c8e18fcd90fc3f

Then enter this to console:

$ bees config:set MYSQL_URL_DB="cloudbees://devels--1"
$ bees config:set MYSQL_USERNAME_DB="devels--1"
$ bees config:set MYSQL_PASSWORD_DB="e00c73c055b545a2b9c8e18fcd90fc3f"

Problem: Online version not working

Solution 0: Set fix values to database in conf/application.conf

  • Does not work! 
! @6do3ie4go - Internal server error, for (GET) [/] ->
...
Caused by: java.lang.UnsupportedClassVersionError: controllers/routes at views.html.index$.apply(index.template.scala:30) ~[develsplay_2.10-1.0.jar:1.0]

Solution 1: Add Jenkins envinject plugin. … TODO …

Play Commands

Start Play console for application:

/path/2/app $ play

Run the application:

[app] $ run
||
/path/2/app $ play run

Compile the app:

[app] $ compile

View interactive Scala console:

[app] $ console

Scala Commands inside interactive console:

 Start application:

 scala> new play.core.StaticApplication(new java.io.File("."))
 scala> views.html.index.("hello")

Debugging:

/path/2/app $ play debug

Trigger (~) Compilation each time you change a source file:

[app] $ ~ compile

Trigger Run development server next to it each time a source file is changed:

[app] $ ~ run

Trigger Continously test the project each time you modify a source file:

[app] $ ~ test

Clean all generated directories:

/path/2/app $ play clean-all

IDE and Tooling

Eclipse Juno (4.2) Classic und Scala IDE 2.10

Anatomy of a 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

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
Build.scala Application build script
plugins.sbt sbt plugins
lib  Unmanaged libraries dependencies 
logs  Standard logs folder 
application.log Default log file
target  Generated stuff 
scala-2.9.1
 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

Scala

Programing Language which enables easy extension with a custom DSL (f.e. to define new language constructs, new functions, …).

JAVA AND SCALA COMPARED: DEFINING A CLASS

// this is Java class MyClass { private int index; private String name; public MyClass(int index, String name) { this.index = index; this.name = name; } } // In Scala, you would likely write this instead: class MyClass(index: Int, name: String)

FURTHER REFERERENCES

References