Play 2 Java Tutorial

Update: This tutorial is a bit old. For more up-to-date tutorials see:

I’ve created a Play 2 Tutorial and posted it on GitHub! The tutorial covers how to:

Each section has a corresponding branch in git so you can diff against my version to see if you’ve done everything correctly. Right now this is just for Play 2 with Java and Ebean but I’m working on doing this for Play 2 with Scala as well.

You can see a live demo of the final app at:

It’s a pretty simple app but it should get you started building Play 2 apps and deploying them on the cloud with Heroku. If you want to take the shortcut to the end and get your own copy of the app running on Heroku then just do the following:

  1. Install git and the Heroku Toolbelt.
  2. Signup for an account on Heroku. (Don’t worry, this stuff is free.)
  3. Clone the play2torial git repo:
    git clone git://
  4. Login to Heroku:
    heroku login
  5. Create a new app on Heroku (from within the play2torial directory):
    heroku create
  6. Upload the app to Heroku (from within the play2torial directory):
    git push heroku origin/java-heroku_update:refs/heads/master
  7. Check out your app on the cloud:
    heroku open
  8. If you want to run the app locally, install Play 2 and then run:
    git checkout java-heroku_update
    play ~run

I hope this helps you learn Play 2! Let me know if you have any questions or comments. Thanks!

  • Jeremias Santos

    Excellent post … I’ll take and do they still have not used the Play! 2.

    BTW, could I point to some tutorial on how to add a project already created locally onHeroku?

    I have an application created in Play! using MySQL and am having difficulty adding it toHeroku, I saw some videos, but only created by the project and Heroku importanto for Eclipse, I want the process is reversed.

    Thanks in advance.

    • You can definitely run an existing Play app on Heroku.  The instructions should be the same, just skip the “play new foo” step.  To setup MySQL check out the MySQL providers in the Heroku Add-on Catalog:

      If you need help, ask on StackOverflow or email me.

      • Jeremias Santos

        My difficulty is already in the application to deploy to Heroku. I saw some videos that you made, but the ones I saw are the process of creating the application Play! in Heroku and import into Eclipse and then make the submissions of the versions. But I want to add my project that already exists in eclipse to Heroku. Is there any video for that process?

        Thank you!

        • I see.  Right now you will need to do some command line stuff (like above).  But once you get everything setup you will be able to do the git push from Eclipse.  Email me if you need help.

  • Hi James, 

    I am running into the following error while trying to push to heroku:

    WARNING: Play! version not specified in dependencies.yml. Default version: 1.2.4 being used

    How do I tell Heroku that I want it to use Play! 2.o? I tried putting a dependencies.yml file in the conf folder with the same information that would have been acceptable for 1.x versions but, no fuzzy bunny. Any help would be much appreciated.


    • Nicolay Hvidsten

      Just in case someone else has similar problems: we solved this by adding the Play! 2 project folder into the root folder that was pushed to Heroku.

  • Jfak20

    Thanks you very much for the tutorial, it works very well! 

  • Pingback: » My experience with the Play Framework Vamsi Velampati()

  • Pingback: Tutorial: Play Framework, JPA, JSON, jQuery, & Heroku()

  • Rajiv Nair

    Awesome! Thanks v much.

  • xxor

    on step 6 it says: error: src refspec java-heroku_update does not match any.

    • Whoops. Sorry about that. Try:
      git push heroku origin/java-heroku_update:refs/heads/master

  • fragment

    ok I ran into few problems… the biggest one being this:

    “ValidationException: Call to TraversableResolver.isReachable() threw an exception”

    it gives when I try to add the validation step, the last one before deploying. I can’t figure out how to repair it. Do you have a clue?

    • Did you diff your code with my code on GitHub? Any differences?

  • Frank Krutik

    Hello James,

    it it possible for you to contact me off topic for the following “challenge” ? I have a Java Smartclient with has on the left a Module List like the Zentask example. Every module has a tree structure and if you click one of the nodes the content area is filled with the matching View. The modules are authenticated and are only visible if the logged on user has the matching rights. I want to rebuild the Java Smart Client with the play framework 2 based on zentasks example. How can i build up real play framework modules, which are presented in the left panel if the user is logged on and authorized and how to show the corresponding views in content area ?

    Thanxs a lot.

    Regards, Frank

    • Hi Frank,

      Can you email me: james.ward at typesafe dot com


  • Jose Mendez

    Hello James, Great post! I’m trying to upload a Play Project to Heroku, however the build keeps timing out after 15 minutes, What should I do? Any pointers will be appreciated :)

  • Pingback: Getting Started with Play Framework on Heroku()

  • alota takada

    I’m trying to do the 8 steps you outline at the bottom. On step 6 (git push) I get an error. I followed your steps exactly. Here is a pastebin with the output from doing the git push:

    • The `(bad constant pool tag 18 at byte 10)` error usually indicates some kind of mismatch between JDK versions and library dependencies. The first thing to try is to downgrade the JDK Heroku is using to 1.7 since I vaguely remember there being an incompatibility with older versions of Play / Scala and JDK 8. Docs on that:

      • alota takada

        I just noticed your disclaimer at the top that the tutorial is a bit old. Is that why downgrading to 1.7 might be necessary?

        I’m wondering if you could recommend a tutorial or template for Play Java, that is up-to-date for Play 2.3.x, that demonstrates how to use CoffeeScript, LESS, RJS, GZIP, Digest, JSHint? Also using Hibernate, JPA & PostGres. And finally Webjars.

        Some things I find confusing:

        1) The SBT Plugins such as sbt-rjs (, say I need this configuration line:

        lazy val root = (project in file(“.”)).enablePlugins(SbtWeb)

        Each example app/template I’ve seen though has:

        lazy val root = (project in file(“.”)).enablePlugins(PlayJava)

        So should it instead be?:

        lazy val root = (project in file(“.”)).enablePlugins(PlayJava, SbtWeb)

        2) How the Pipeline configuration works. In I found the following line:

        pipelineStages := Seq(rjs, digest, gzip)

        How would Less, CoffeeScript, JSHint work within the pipeline? Do they not need to be added to the Pipeline?

        3) What is the Build.scala file? Your other tutorial references this here:

        When I create a new Play Java App using Activator there isn’t a Build.scala file in the root or project directory. I only have build.sbt in the root directory and plugins.sbt in the /project directory.

        Along those same lines should I be doing something like this:

        val appDependencies = Seq(
        “org.webjars” % “webjars-play” % “2.0”,
        “org.webjars” % “bootstrap” % “2.1.1”

        Or do Webjars now go directly into libraryDependencies like:

        libraryDependencies ++= Seq(
        “org.webjars” %% “webjars-play” % “2.3.0-2”,
        “org.webjars” % “bootstrap” % “3.1.1-2”

        4) SBT Plugins vs WebJars? For RequireJS for example, its unclear if I should be using it as a WebJar or SBT Plugin. In the Play Documentation for Assets here it says to use RequireJS as a WebJar (under the WebJars section). Here is a specific line:

        “For example if you declared a dependency on RequireJs then you can reference it from a view using a line like:”


        But 3 pages later in the Assets documentation for “Using RequireJS” ( it says to setup as an SBT Plugin with some sort of Pipeline configuration.

        Which is the recommended way?

        Thanks and sorry for the long list of questions!

        • I don’t think there is a single template that has all of that in one place. Maybe you could create it! I’m sure you could combine pieces of different templates from:

          Answers to your questions:

          1) It is sufficient to do:

          lazy val root = (project in file(“.”)).enablePlugins(PlayJava)

          If you have the sbt-web stuff in project/plugins.sbt then it will be enabled automatically

          2) Yes, I think they should be added to the pipeline. More info on the pipeline:

          3) build.sbt is the newer and recommended build definition, replacing Build.scala in newer versions of Play. The WebJar dependencies go in the libraryDependencies part of the build.sbt file. More info in the docs:

          4) Depends on whether you want everything concatenated together or not. I prefer to keep WebJars out of my app js file. So I don’t use sbt-rjs. But others do.