Skip to content
ratulb edited this page May 13, 2012 · 97 revisions

Play 2.0 documentation

Play 2.0 is a high-productivity Java and Scala web application framework that integrates the components and APIs you need for modern web application development.

Play is based on a lightweight, stateless, web-friendly architecture and features predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications thanks to its reactive model, based on Iteratee IO.

About

  1. Play 2.0 a Web framework for a new era

Getting started

  1. Installing Play 2.0
  2. Creating a new application
  3. Anatomy of a Play 2.0 application
  4. Using the Play 2.0 console
  5. Setting-up your preferred IDE
  6. Sample applications

Working with Play 2.0

  1. Play 2.0 for Scala developers
  2. Play 2.0 for Java developers

Detailed topics

  1. The Build system
    1. About sbt settings
    2. Manage application dependencies
    3. Working with sub-projects
  2. Working with public assets
    1. Using CoffeeScript
    2. Using LESS CSS
    3. Using Google Closure Compiler
  3. Managing database evolutions
  4. Configuration file syntax and features
    1. Configuring the JDBC connection pool
    2. Configuring the internal Akka system
    3. Configuring logging
  5. Deploying your application
    1. Creating a standalone version of your application
    2. Additional configuration
    3. Deploying to Heroku
    4. Set-up a front-end HTTP server

Additional documentation

  1. Scala
  2. Akka
  3. sbt
  4. Configuration
  5. Logback

Hacking Play 2.0

  1. Building Play 2.0 from source
  2. CI server at Cloudbees
  3. Repositories
  4. Issue tracker
  5. Pull requests
  6. Contributor guidelines

Modules and plugins

  1. Temporary modules directory

User groups

  1. User groups around the world

Contributing to this documentation

The documentation is freely editable on https://github.com/playframework/Play20/wiki. Feel free to fix mistakes directly in the pages.

However if you want to provide additional documentation, please create new pages and reference them from here. A member of the core team will take care of integrating it in the most appropriate section.

Deploy play 2.0 app on cloudfoundry:

Prerequisite:

Before you can deploy your app in cloudfoundry.com - you need to open an account with cloudfoundry.com. After registering it takes a day or two to get your account activated. You also have to have either the vmc command line tool or STS (eclipse plugin) installed on your system - visit the http://docs.cloudfoundry.com/getting-started.html link and follow the instructions there.

Once you have setup the pre-requisites and got your user name and password from cloudfoundry.com - you are all set to deploy your app on cloudfoundry.com Paas.

I am going to use the vmc command line tool to deploy a newly created play 2.0 application on cloudfoundry.

Follow the steps below to deploy your app.

  1. Launch command prompt.

  2. Type in -> play new myPlayApp

ratul@ubuntu:~$ play new myPlayApp _ _ _ __ | | __ _ _ | | | ' | |/ ' | || || | /||_|__ () || |__/

play! 2.0.1, http://www.playframework.org

The new application will be created in /home/ratul/myPlayApp

What is the application name?

myPlayApp

Which template do you want to use for this new application?

1 - Create a simple Scala application 2 - Create a simple Java application 3 - Create an empty project

1

OK, application myPlayApp is created.

Have fun!

  1. Opne the newly created myPlayApp/app/controllers/Application.scala file in a text editor.

Change defintion of the index method like so:

def index = Action { val port = System.getenv("VCAP_APP_PORT") val host = System.getenv("VCAP_APP_HOST") println("App port : "+ port+" and host: "+ host) Ok(views.html.index("Your new application is ready."+ "App port : "+ port+" and host: "+ host)) }

Note: VCAP_APP_PORT & VCAP_APP_HOST are port name host names cloudfoundry assigns when it runs your app.

  1. Save the Application.scala.

  2. Open the myPlayApp/app/views/index.scala.html in a text editor and change the line that reads @play20.welcome(message) to @message and save it.

  3. On the command, cd myPlayApp -> ratul@ubuntu:~$ cd myPlayApp/

  4. launch the play promt by tying 'play'.

ratul@ubuntu:~/myPlayApp$ play [info] Loading project definition from /home/ratul/myPlayApp/project [info] Set current project to myPlayApp (in build file:/home/ratul/myPlayApp/) _ _ _ __ | | __ _ _ | | | ' | |/ ' | || || | /||_|__ () || |__/

play! 2.0.1, http://www.playframework.org

Type "help play" or "license" for more information. Type "exit" or use Ctrl+D to leave this console.

  1. Next we will bundle the application. So type 'dist' on the play prompt.

[myPlayApp] $ dist [info] Updating {file:/home/ratul/myPlayApp/}myPlayApp... [info] Done updating.
[info] Compiling 5 Scala sources and 1 Java source to /home/ratul/myPlayApp/target/scala-2.9.1/classes... [info] Packaging /home/ratul/myPlayApp/target/scala-2.9.1/myPlayApp_2.9.1-1.0-SNAPSHOT.jar ... [info] Done packaging.

Your application is ready in /home/ratul/myPlayApp/dist/myPlayApp-1.0-SNAPSHOT.zip

[success] Total time: 12 s, completed 12 May, 2012 2:56:34 PM

  1. We want to push the application contents as folder structure and not as zip so that we want to be able to push deltas later on. Hence open the folder myPlayApp/dist in your explorer and extract the contents inside 'myPlayApp-1.0-SNAPSHOT.zip' in the same folder.

  2. Delete the myPlayApp-1.0-SNAPSHOT.zip. Go inside the myPlayApp-1.0-SNAPSHOT folder and delete the README and start files as well - we do not need them.

  3. Now we are ready to push our content to cloudfoundry. Let's login cloudfoundry first.

  4. On the command prompt come out from the play promt by typing 'exit'.

  5. cd dist/myPlayApp-1.0-SNAPSHOT/

  6. Type 'vmc login' on the command prompt.

ratul@ubuntu:~/myPlayApp/dist/myPlayApp-1.0-SNAPSHOT$ vmc login Attempting login to [http://api.cloudfoundry.com]

Email: [email protected] Password: ****************** Successfully logged into [http://api.cloudfoundry.com]

  1. On the prompt type : vmc target api.cloudfoundry.com

ratul@ubuntu:~/myPlayApp/dist/myPlayApp-1.0-SNAPSHOT$ vmc target api.cloudfoundry.com Successfully targeted to [http://api.cloudfoundry.com]

  1. When prompted by vmc, answer with y or n as shown below.

ratul@ubuntu:~/myPlayApp/dist/myPlayApp-1.0-SNAPSHOT$ vmc push Would you like to deploy from the current directory? [Yn]: y Application Name: myPlayApp Detected a Standalone Application, is this correct? [Yn]: y 1: java 2: node 3: node06 4: ruby18 5: ruby19 Select Runtime [java]: 1 Selected java Start Command: java $JAVA_OPTS -Dhttp.port=$VCAP_APP_PORT -cp "dirname $0/lib/*" play.core.server.NettyServer dirname $0 Application Deployed URL [None]: myPlayApp.${target-base}
Memory reservation (128M, 256M, 512M, 1G, 2G) [512M]: 256M How many instances? [1]: 1 Create services to bind to 'myPlayApp'? [yN]: n Would you like to save this configuration? [yN]: y Manifest written to manifest.yml. Creating Application: OK Uploading Application: Checking for available resources: OK Processing resources: OK Packing application: OK Uploading (80K): OK
Push Status: OK Staging Application 'myPlayApp': OK
Starting Application 'myPlayApp': OK

ratul@ubuntu:~/myPlayApp/dist/myPlayApp-1.0-SNAPSHOT$

  1. In your browser you can now open your application - type in myPlayApp.cloudfoundry.com - and we are done!

  2. The broswer will show something like :

Your new application is ready.App port : 61897 and host: 172.30.50.24

###Needs to be integrated Play 2.0 for Play 1.x developers

Clone this wiki locally