Play 2 Java Tutorial

Update: This tutorial is a bit old. For more up-to-date tutorials see: https://www.playframework.com/documentation/2.3.x/Tutorials

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:
play2torial.herokuapp.com

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://github.com/jamesward/play2torial.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!

This entry was posted in Java, Play Framework. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
  • 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.

    • http://www.jamesward.com James Ward

      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: http://addons.heroku.com

      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!

        • http://www.jamesward.com James Ward

          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.

          • Jeremias Santos

            I watched this video 
            http://www.jamesward.com/2012/03/15/screencast-java-template-apps-on-heroku . You do have some process that talked or even a tutorial on how tolead a project has made ​​local to the Heroku, or send it to Heroku and configure eclipsefor contole version?
            Once again thank you for your attention. 

          • http://www.jamesward.com James Ward

            Just command line stuff for now.  Send me an email jw at heroku dot com and I can help you figure out how to get everything setup.

          • Jeremias Santos

            I sent the mail to jw@heroku.com.

            Thank you!

  • http://twitter.com/stevenelliottjr Steven Elliott

    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.

    Thanks!

    • 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.

    • http://www.jamesward.com James Ward

      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?

    • http://www.jamesward.com James Ward

      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

    • http://www.jamesward.com James Ward

      Hi Frank,

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

      Thanks!

  • 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



  • View James Ward's profile on LinkedIn