In this blog we would set up the development environment with Play and Eclipse which would drive us through rest of the tutorial series. We would be running this blog as a series and we would be looking at various aspects of play with this blog.
In this tutorial we will discuss about the following topics of Play Framework:
- Installing Play
- New application
- Layout of Play application
- Play console
- Setting-up Eclipse
∗ Installing Play
Prerequisites: To run the Play framework, you need JDK 6 or later
Step-1: Download Activator from here
Step-2: Go to the ZIP file path and UNZIP it
anand@anand-singh:~$ cd softwares/ anand@anand-singh:~/softwares$ unzip typesafe-activator-1.2.10-minimal.zip Archive: typesafe-activator-1.2.10-minimal.zip creating: activator-1.2.10-minimal/ inflating: activator-1.2.10-minimal/activator.bat inflating: activator-1.2.10-minimal/activator inflating: activator-1.2.10-minimal/activator-launch-1.2.10.jar anand@anand-singh:~/softwares$
Step-3: Set the activator to your path
anand@anand-singh:~$ vi .bashrc export TYPESAFE_ACTIVATOR=/home/anand/softwares/activator-1.2.10-minimal export PATH=$PATH:$TYPESAFE_ACTIVATOR To check anand@anand-singh:~$ which activator /home/anand/softwares/activator-1.2.10-minimal/activator
Step-4: Check the activator command
anand@anand-singh:~$ activator -help
Now your system is ready to create a new Play application.
NOTE: If you don’t want to setup the activator into your path then just unzip and go to the activator script path and use it.
anand@anand-singh:~$ cd softwares/activator-1.2.10-minimal/ anand@anand-singh:~/softwares/activator-1.2.10-minimal$ ./activator -help The result of "./activator -help" command is same like above screen.
∗ New application
There are several way to create new application using activator command:
$ activator new play-scala-tutorial-one play-scala
$ activator new play-scala-tutorial-one
∗ Layout of Play application
∗ Play Console
$ cd play-scala-tutorial-one $ activator [info] Loading project definition from /home/anand/projects/knoldus/play-scala-tutorial-one/project [info] Set current project to play-scala-tutorial-one (in build file:/home/anand/projects/knoldus/play-scala-tutorial-one/) [play-scala-tutorial-one] $ To Help: [play-scala-tutorial-one] $ help run Runs a main class, passing along arguments provided on the command line. [play-scala-tutorial-one] $ help compile Compiles sources. [play-scala-tutorial-one] $ To Compile: [play-scala-tutorial-one] $ compile [success] Total time: 0 s, completed 3 Oct, 2014 12:11:34 PM [play-scala-tutorial-one] $
The Play console is just a normal sbt console, so you can use sbt features such as triggered execution.
For example, using
] $ ~ compile
The compilation will be triggered each time you change a source file.
If you are using
] $ ~ run
The triggered compilation will be enabled while a development server is running.
You can also do the same for
~ test, to continuously test your project each time you modify a source file:
] $ ~ test
∗ Setting-up Eclipse
] $ eclipse
Import the application into your Workspace with the File/Import/General/Existing project… menu (compile your project first).
This is the start of tutorial series, from next week onwards we would be working on this tutorial blog to make it grow. We would look at how we can make it more usable and readable, then we would be adding next tutorial of “Using Bootstrap, Bootswatch and WebJars with Play application”. If you have any question then feel free to comment on the same 🙂 Stay tuned.