Play Framework 2 Tutorial: Introduction
How to create a simple Play Framework application and deploy it to Heroku. Helpful screenshots and complete source code is available for download.
I’ve been putting off learning the Play Framework because I wasn’t sure it was going to be just another framework that’s here today and forgotten tomorrow. As of the time this post was written it seems that Play is not just another framework and is in fact gaining a lot of traction (especially since version 2.0). In fact it’s a framework that’s now supported by a couple of my favorite PaaS providers such as Heroku and CloudFoundry.
So here’s an introductory tutorial of how to get a basic “Hello World” app running and deployed to Heroku.
It’s assumed that you have the following installed and available on your workstation:
- install git
- install play
- install heroku toolbelt
Creating the app
We start by creating a very basic skeletal application. I’ve decided to name my app “finances”.
cd ~/projects (or wherever you’d like to create your new app)
- cd finances
- git init
Updating the app
Beyond the skeleton app created via “play new finances”, here are some changes to make via your favorite text editor:
Create app/controllers/Application.java with the following content:
Update project/Build.scala (adding the mainLang argument to the PlayProject method)
Run and verify the app locally
- from the project root (~/projects/finances in my case), run
- open a browser to http://localhost:9000 (the default port is 9000)
Deploying to Heroku
Now that you’ve verified the app locally, you can deploy it to Heroku:
- git add .
- git commit -am “init”
- heroku create finances-staging –stack cedar
- git push heroku master
You can download or fork the complete source for this tutorial at GitHub.