New Play! App

Create a new Play site:

 
c:> play new MySite 
~        _            _
~  _ __ | | __ _ _  _| |
~ | ‘_ | |/ _’ | || |_|
~ |  __/|_|____|__ (_)
~ |_|            |__/   
~
~ play! 1.2.1, http://www.playframework.org
~
~ The new application will be created in /home/frederic/Projects/Java/play/MySite
~ What is the application name? [MySite]
~
~ OK, the application is created.
~ Start it with : play run MySite
~ Have fun!

 

Dependencies

see here for more information http://www.playframework.org/documentation/1.2.1/dependency
Edit dependencies with the dependencies.yml file:

 
requires:
    – play ->[1.2, )
    – play -> crud -> [1.1, )
    – play -> secure -> [1.1, )


and launch following command to retrieve these dependencies/ modeles from repositories.

c:> play dependencies
~        _            _
~  _ __ | | __ _ _  _| |
~ | ‘_ | |/ _’ | || |_|
~ |  __/|_|____|__ (_)
~ |_|            |__/   
~
~ play! 1.2.1, http://www.playframework.org
~
~ Resolving dependencies using /home/frederic/Projects/Java/play/MySite/conf/dependencies.yml,
~
~
~ Some dynamic revisions have been resolved as following,
~
~    play->play [1.2,) will use version 1.2.1
~
~ Installing resolved dependencies,
~
~     modules/crud -> /home/frederic/Tools/java/tools/play-1.2.1/modules/crud
~     modules/secure -> /home/frederic/Tools/java/tools/play-1.2.1/modules/secure
~
~ Done!
~

Edit !

What you will find in your favorite code editor :

Application

figure 1 – A new Play! app just created

 

 

You can install a gedit plugin to integrate the Zen Coding features. Just got to the following github repo :


https://github.com/mikecrittenden/zen-coding-gedit

 

Just download the proposed zip file and unzip it into the .gnome2/gedit/plugins folder.
Restart gedit if it’s already running.

you will get the plugin ready to use.

But with some more tricky operation, you will be able to work with Eclipse or NetBeans in really easy way:

Eclipse

c:> cd MySite
c:> play eclipsify
 
 
And then import the existing project into Eclipse, and new files appear in the project directory:

Slection_011

 

figure 2 – « Eclipsifyed » Play! project

 

Then, import the project into a brand new workspace and follow these steps:

1. import from Project explorer contextual menu :

Menu_015

figure 2.1 – Eclipse « Import… » menu

2. Choose « Existing projects into workspace »

Import_016

figure 2.2 – The « Existing Projects into Workspace » wizard
3. Browse to your project path and semect the detected Eclipse Project:

Import_017

figure 2.3 – Detected project into browsed directory.

And click the « Finich » Button to discover you fresh imported project into your current workspace:

Java_-_mysite-app-controllers-

figure 2.4 – Play! project importer into Eclipse, ready at work !

NetBeans
As easy as for Eclipse, you just have to use the magic command:
 
c:>cd MySite
c:> play netbeansify
 
 
And then, the directory structure is modified as shown bellow:

Slection_012

figure 3 – « NetBeansify’ed » Play! project

 

 

Run , start and stop

Run a play app:
 
c:> play run
~        _            _
~  _ __ | | __ _ _  _| |
~ | ‘_ | |/ _’ | || |_|
~ |  __/|_|____|__ (_)
~ |_|            |__/   
~
~ play! 1.2.1, http://www.playframework.org
~
~ Ctrl+C to stop
~
Listening for transport dt_socket at address: 8000
23:52:32,877 INFO  ~ Starting /home/frederic/Projects/Java/play/MySite
23:52:32,915 INFO  ~ Module secure is available (/home/frederic/Tools/java/tools/play-1.2.1/modules/secure)
23:52:32,915 INFO  ~ Module crud is available (/home/frederic/Tools/java/tools/play-1.2.1/modules/crud)
23:52:34,026 WARN  ~ You’re running Play! in DEV mode
23:52:34,267 INFO  ~ Listening for HTTP on port 9000 (Waiting a first request to start) …

 
Or you can use the other command to not lock current terminal:
 
C:> play start
~        _            _

~  _ __ | | __ _ _  _| |
~ | ‘_ | |/ _’ | || |_|
~ |  __/|_|____|__ (_)
~ |_|            |__/   
~
~ play! 1.2.1, http://www.playframework.org
~
~ OK, /home/frederic/Projects/Java/play/MySite is started
~ output is redirected to /home/frederic/Projects/Java/play/MySite/logs/system.out
~ pid is 19948
~

 
you can note the pid value, here 19948 (in case of manual kill action ?  🙂
And then you will be able to stop this play server with a :
 
c:> play stop
~        _            _
~  _ __ | | __ _ _  _| |
~ | ‘_ | |/ _’ | || |_|
~ |  __/|_|____|__ (_)
~ |_|            |__/   
~
~ play! 1.2.1, http://www.playframework.org
~
~ OK, /home/frederic/Projects/Java/play/MySite is stopped
~

Browse

And then, open you favorite (sic) browser and ask for the http://localhost:9000/ url:

Your_application_is_ready_-_mo

figure 4 – Browser on a new Play! running project

 

Play help ?

At any time,you are able to run the famous help command:
 
c:> play help
 
And the you will be free as bird to parse excellent documentation provided by the play distributed archive.
 
sample:
 
~        _            _
~  _ __ | | __ _ _  _| |
~ | ‘_ | |/ _’ | || |_|
~ |  __/|_|____|__ (_)
~ |_|            |__/   
~
~ play! 1.2.1, http://www.playframework.org
~
~ For all commands, if the application is not specified, the current directory is used
~ Use ‘play help cmd’ to get more help on a specific command
~
~ Core commands:
~ ~~~~~~~~~~~~~~
~ auto-test       Automatically run all application tests
~ build-module    Build and package a module
~ check           Check for a release newer than the current one
~ classpath       Display the computed classpath
~ clean           Delete temporary files (including the bytecode cache)
~ crud:override   Override a view
~ dependencies    Resolve and retrieve project dependencies
~ eclipsify       Create all Eclipse configuration files
~ evolutions      Run the evolution check

~ evolutions:applyAutomatically apply pending evolutions
~ evolutions:markAppliedMark pending evolutions as manually applied
~ evolutions:resolveResolve partially applied evolution
~ help            Display help on a specific command
~ id              Define the framework ID
~ idealize        Create all IntelliJ Idea configuration files
~ install         Install a module
~ javadoc         Generate your application Javadoc
~ list-modules    List modules available from the central modules repository
~ modules         Display the computed modules list
~ netbeansify     Create all NetBeans configuration files
~ new             Create a new application
~ new-module      Create a module
~ out             Follow logs/system.out file
~ pid             Show the PID of the running application
~ precompile      Precompile all Java sources and templates to speed up application start-up
~ restart         Restart the running application
~ run             Run the application in the current shell
~ secret          Generate a new secret key
~ secure:         Show help for the secure module
~ secure:override Override the CSS, login or layout
~ start           Start the application in the background
~ status          Display the running application’s status
~ stop            Stop the running application
~ test            Run the application in test mode in the current shell
~ war             Export the application as a standalone WAR archive
~
~ Also refer to documentation at http://www.playframework.org/documentation

 
for more information, please, refer to the official web site : http://www.playframework.org/documentation/1.2.1/home

Or if you already have a running Play! project, just try to open the http://localhost:9000/@documentation

Play_manual_-_documentation_-_

figure 5 – At any time, just display the provided help


Test
Play! integrate also a Test running mode to be able to execute JUnit tests and UI test through defined test cases. To run play developpement server into such a mode, just
 input following line int to a Terminal (or Command DOS/Session on Windows):

C:> play test

Then open your browser on the http://localhost:9000/@tests and the following page will be displayed:

Play_-_tests_runner_-_mozilla_

figure 6 – Test mode for Play! server
Publicités