In four easy steps, we can install Play and get it set up on our system.
Before you install Play, you need to check if JDK 6 or later is installed, which can be downloaded here: http://www.oracle.com/technetwork/java/javase/downloads
Tip
The JDK should be pre-installed on Mac OS X and Linux. The OpenJDK, a viable open-source alternative to the Oracle JDK, is already a part of many Linux distributions. Windows users should download and install the latest JDK as mentioned previously.
This is the only requirement. Play is bundled with its own web server and build environment, so we don't have to install additional software.
As mentioned previously, Play provides more than just an API for programming web applications—Play is a full-stack web framework that also takes care of building and running your application. You can use your preferred editor or IDE to develop a Play application. Modifications to your source code are automatically detected and the running application is refreshed by Play.
The easiest way to download Play is as a compressed package from http://www.playframework.org/download.
Tip
For Mac users with Homebrew installed, it's even easier to install Play. The command brew install play
will install the latest version of Play and set the PATH
environment variable accordingly. For managing multiple versions of Play, it is definitely worth taking a look at https://github.com/kaiinkinen/pvm.
We suggest that you download the most current stable build. After downloading, the archive has to be unpacked to a place where you have read and write permissions. This is necessary because Play caches all library dependencies in a file system repository. After unpacking the archive, you will be left with a directory called play-2.1
or similar, depending on the downloaded version. The extracted directory contains a number of files and folders.
/path/to/play | CONTRIBUTING.md instructions for committing code | README.md basic instructions on using Play | play Mac/Linux start script | play.bat Windows start script |-documentation manual and API specification |-framework Play project files and sources |-repository downloaded dependencies |-samples sample application for Java and Scala
Here you find the Play start scripts play
for Mac/Linux and play.bat
for Windows. The documentation
folder contains the user manual and the API specification, which will accompany you when developing an application. In the samples
folder, you will find the source code of the examples shipped with Play. They are a great learning resource when you have understood the basics of Play and want to go further, so take a look at them. Both the documentation and the samples are available for Java and Scala developers.
The remaining folders are of less interest to us in this book; framework
contains the Play project files and sources and repository
contains additional downloaded libraries and dependencies.
Before creating our first Play application, we have to ensure that the Play installation directory is added to the system path. This makes it possible to start Play from the console without specifying the complete path of the start
script.
Please open a text editor of your choice. Depending on the underlying OS, the PATH
environment variable is set up as follows:
Mac OS: To set up the
PATH
environment variable, add the lineexport PATH=$PATH:/path/to/play
to the file~/.bash_profile
, where/path/to/play
points to the location where you have installed Play.Linux: To set up the
PATH
environment variable, add the lineexport PATH=$PATH:/path/to/play
to your shell configuration file, for example, add the line to~/.bashrc
if you use the bash shell. Again,/path/to/play
points to the Play installation directory.Windows: To permanently add Play to your environment settings, open a terminal window and execute the following command:
setx PATH "%PATH%;c:\path\to\play" -m
. Please change the pathc:\path\to\play
according to the path of your Play installation directory.
Now we are ready to start Play. Test your installation by opening a new command-line window. Then type the play
command. The Play script should produce output on the screen similar to this:
The output of the play
script shows us the error message This is not a play application!. You will see that it is characteristic for Play to provide hints for fixing errors. In this case Play gives us two options:
Use
play new
to create a new Play application in the current directoryGo to an existing application and launch the development console using
play
We will discuss both topics in the next section.