Saturday, August 1, 2015

First application using Play Framework

First application using Play Framework:

Before going to implement the First play application, we need to know some thing about activator and it's commands:

Activator:  
  • Typesafe Activator is a browser based or command line tool that helps developers get started with the Typesafe Reactive Platform.
  • Activator includes the sbt build tool, a quick-start GUI, and a catalog of template applications
  • Activator allows us to select a template that our new application should be based off.  The names of the templates are play-scala for Scala based Play applications and play-java for Java based Play applications.
The following are the important commands of activator:
Command name Description
activator To run the Console
activator ui Start the Activator UI
activator new [name] [template-id] Create a new project with [name] using template [template-id]
activator list-templates Print all available template names
activator help Print this message

Creating the new application:
To create a new applications we need to use the activator new command.

D:\Play\My_Practise>activator new HelloWorld
Fetching the latest list of templates...

Browse the list of templates: http://typesafe.com/activator/templates
Choose from these featured templates or enter a template name:
1) minimal-akka-java-seed
2) minimal-akka-scala-seed
3) minimal-java
4) minimal-scala
5) play-java
6) play-scala

(hit tab to see a list of all templates)
> 5
OK, application "HelloWorld" is being created using the "play-java" template.

To run "HelloWorld" from the command line, "cd HelloWorld" then:
D:\Play\My_Practise\HelloWorld/activator run

To run the test for "HelloWorld" from the command line, "cd HelloWorld" then:
D:\Play\My_Practise\HelloWorld/activator test

To run the Activator UI for "HelloWorld" from the command line, "cd HelloWorld" then:

D:\Play\My_Practise\HelloWorld/activator ui

Project Structure:



Compiling the Project:
By using activator compile command, we can compile our application without running the server.

D:\Play\My_Practise\HelloWorld>activator compile
[info] Loading project definition from D:\Play\My_Practise\HelloWorld\project
[info] Updating {file:/D:/Play/My_Practise/HelloWorld/project/}helloworld-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to HelloWorld (in build file:/D:/Play/My_Practise/HelloWorld/)
[info] Updating {file:/D:/Play/My_Practise/HelloWorld/}root...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 6 Scala sources and 2 Java sources to D:\Play\My_Practise\HelloWorld\target\scala-2.11\classes...
[success] Total time: 135 s, completed Jul 29, 2015 11:52:10 PM

Running the Project:
By using activator run command, we can run the application.

D:\Play\My_Practise\HelloWorld>activator run
[info] Loading project definition from D:\Play\My_Practise\HelloWorld\project
[info] Set current project to HelloWorld (in build file:/D:/Play/My_Practise/HelloWorld/)

--- (Running the application, auto-reloading is enabled) ---

[info] p.a.l.c.ActorSystemProvider - Starting application default Akka system: application
[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...)


Testing the Project:
By using activator test command, we can test the application.

D:\Play\My_Practise\HelloWorld>activator test
[info] Loading project definition from D:\Play\My_Practise\HelloWorld\project
[info] Set current project to HelloWorld (in build file:/D:/Play/My_Practise/HelloWorld/)
Warning: node.js detection failed, sbt will use the Rhino based Trireme JavaScript engine instead to run JavaScript assets compilation, which in some cases may be orders of magnitude slower than using node.js.
[info] Compiling 2 Java sources to D:\Play\My_Practise\HelloWorld\target\scala-2.11\test-classes...
[info] D:\Play\My_Practise\HelloWorld\test\ApplicationTest.java: D:\Play\My_Practise\HelloWorld\test\ApplicationTest.java uses or overrides a deprecated API.
[info] D:\Play\My_Practise\HelloWorld\test\ApplicationTest.java: Recompile with -Xlint:deprecation for details.
[info] - application - Creating Pool for datasource 'default'
[info] - play.api.libs.concurrent.ActorSystemProvider - Starting application default Akka system: application
[info] - play.api.libs.concurrent.ActorSystemProvider - Shutdown application default Akka system: application
[info] - application - Shutting down connection pool.
[info] Passed: Total 3, Failed 0, Errors 0, Passed 3
[success] Total time: 18 s, completed Jul 30, 2015 12:00:49 AM

Debugging the Project:
By using following command, we can debug the application.
activator -jvm-debug <port> 

$ activator -jvm-debug 9999
When a JPDA port is available, the JVM will log this line during boot:
Listening for transport dt_socket at address: 9999

Happy Coding!

Related Posts:

  • First application using Play FrameworkFirst application using Play Framework:Before going to implement the First play application, we need to know some thing about activator and it's commands:Activator:  Typesafe Activator is a browser based or command … Read More
  • Java Frameworks PostsJava Frameworks Posts coming soon....… Read More
  • Play Framework InstallationInstalling Play Framework:The following are the steps to install a play framework:Step 1: In order to run Play framework , we need JAVA 6 or higher versions. To test in your system java is installed or not, use the follo… Read More
  • Play Application StructureThe Structure of a Play Application:The structure of a Play Application is very similar to a other MVC application. There are Models, Views and Controllers folder under the app directory.  In addition to app directory it… Read More
  • About Play FrameworkAbout Play Framework:Play is an open source modern web application framework for writing scalable web applications. It is written in both Scala and Java languages.Play was created by software developer Guillaume Bort, wh… Read More

0 comments: