Getting Started with Play Framework on Heroku

Last week Heroku announced that you can now run Java apps on Heroku. Today Heroku announced that you can also easily run Play Framework apps on Heroku! Here’s a quick guide to getting started with Play! on Heroku:

  1. Install the heroku command line client on Linux, Mac, or Windows.
  2. Install git and setup your SSH key
  3. Install Play! version 1.2.3
  4. Login to Heroku from the command line:

    heroku auth:login
  5. Create a new Play! app:
    play new play_hello_world
    cd play_hello_world
  6. Run the app locally to test it:
    play run --%production
  7. Create a git repo, add the files, and commit:
    git init
    git add app conf lib public test
    git commit -m init
  8. Create a new app on Heroku:
    heroku create -s cedar
  9. Push the app to Heroku:
    git push heroku master
  10. Open the app in your browser:
    heroku open

That’s it! If you want to learn more about Heroku, check out the Heroku for Java Workbook and the Heroku Dev Center. And if you are at Dreamforce 2011 then check out Felipe Oliveira’s session on “Introducing Play! Framework: Painless Java and Scala Web Applications” on Wednesday at 3:30pm.

Let me know what you think and if you have any questions.

This entry was posted in Heroku, Play Framework. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
  • http://sebastien-arbogast.com Sebastien Arbogast

    When I run heroku auth:login on my Mac, I get the following error:

    /usr/local/heroku/lib/heroku/client.rb:2:in `require’: no such file to load — rest_client (LoadError)
    from /usr/local/heroku/lib/heroku/client.rb:2
    from /usr/local/heroku/lib/heroku.rb:6:in `require’
    from /usr/local/heroku/lib/heroku.rb:6
    from /usr/bin/heroku:19:in `require’
    from /usr/bin/heroku:19

    Any idea what that means?

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

      Yeah. Looks like there is a problem with the heroku toolbelt client on Mac. As Jeff said, try to install the heroku client via the gem. Let me know if that works.

    • julien

      Any issues during the heroku install? If so, you might try re-installing the gem and if you have issues, install XCode and development tools and repeat, should be fine.

      • http://sebastien-arbogast.com Sebastien Arbogast

        It worked once I installed the heroku gem. It should be added to all the docs on heroku

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

      BTW: One of the engineers let me know that they have now fixed this issue.

  • http://blog.jeffdouglas.com Jeff Douglas

    I think you need to install the heroku gem:

    gem install heroku

  • http://sebastien-arbogast.com Sebastien Arbogast

    And Play! framework is nice but how about Grails? Since I saw Rails guys using Heroku, Grails on Heroku has been a fantasy of mine. Is there something special required to make it work?

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

      Any Java will run on Heroku. So Grails will certainly work. But I haven’t looked into how to do it yet. Right now you need a pom.xml file to tell Heroku that the app is Java. But from there everything is up to you.

  • Tom Borthwick

    When I run the heroku toolbelt client on Windows 7, I get this error:

    C:\dev\Heroku\\ruby\\bin\\ruby.exe: No such file or directory — C:/dev/Heroku/heroku (LoadError)

    where I installed Heroku into c:\dev. Is there a prerequisite I need to install first?

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

      I’m not sure why you are getting an error. Maybe the PATH setting for Ruby is incorrect. Can you check that?

      • Tom Borthwick

        The toolbelt installer put the Heroku dir on my PATH, but nothing for ruby. I tried running setrbvars.bat in the ruby\bin folder and that added the ruby\bin folder to my PATH, but I get the same result.

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

          Looks like we’ve reproduced this issue. Can you file a support ticket:
          http://support.heroku.com/

          Thanks.

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

      This has been fixed. Can you try to download the toolbelt again and reinstall?

      • Tom Borthwick

        Now I get an error:

        The network path was not found.

        I don’t see any logs that might be useful.

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

          That is when you run the heroku command?

          • Tom Borthwick

            Yes, I was running the heroku command, but I just tried it in a new window and the heroku command worked fine. I must have been using an old window that didn’t get some environment variables set by the toolbelt installer. Oops! Thanks for your help.

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

            Awesome! I’m glad it worked!

      • http://storycatcher.info/AsAperture Aernout

        I have the same problem… Any advice on how to solve this?

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

          So, Tom’s solution above didn’t solve it for you?

  • http://flurdy.com Ivar Abrahamsen

    Getting a port errors when following these steps to deploy the hello world to heroku.
    Also it seems to deploy in DEV mode?

    2011-09-08T21:37:12+00:00 heroku[web.1]: Starting process with command `play run –http.port=25117`
    2011-09-08T21:37:12+00:00 app[web.1]: Listening for transport dt_socket at address: 8000
    2011-09-08T21:37:12+00:00 app[web.1]: 21:37:12,834 INFO ~ Starting /app
    2011-09-08T21:37:12+00:00 app[web.1]: 21:37:12,877 WARN ~ You’re running Play! in DEV mode
    2011-09-08T21:37:12+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 8000, should be 25117 (see environment variable PORT)
    2011-09-08T21:37:12+00:00 heroku[web.1]: Stopping process with SIGKILL
    2011-09-08T21:37:13+00:00 heroku[web.1]: Process exited

    Presume it is an environment setting Im missing?

    • http://flurdy.com Ivar Abrahamsen

      Creating a Procfile and adding: “web: play run –http.port=$PORT $PLAY_OPTS” fixed the problem.

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

        Hi Ivar,

        Thanks for giving it a try! It should have done all of that automatically for you. Are you using Play version 1.2.3?

        -James

        • http://flurdy.com Ivar Abrahamsen

          Using Play 1.2.3. Ran the same steps today, and it worked as expected. No need for a Procfile.

          —–> No Procfile found. Will use process:
          play run –http.port=$PORT $PLAY_OPTS

          Must have been connected to different play dyno version perhaps. Anyway, it works! :)

      • PaquitoSoft

        Hi there!

        I have the same R11 Error and I already have the Profile created.
        Does anyone have any idea?

        Thanks.

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

          Try again. Looks like you might have done this right when there was a service disruption:
          https://status.heroku.com/

  • http://www.heyabbott.net Wayne

    Excellent article, James! I usually do everything in Ubuntu but I even got this to work on my company-issued Windoze laptop using the instructions here. Nice to know there is a cool framework alternative to Rails for us Java guys. Thanks.

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

      Nice! Let me know if there is anything else I can help with.

  • Prathamesh mone

    On windows 7 machine I am trying to deploy a heroku cedar Scala application. In the article on heroku website it talks about foreman to run the app. But when I type it in command prompt I am getting error that its not installed.

    How to install foreman on windows machine.?

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

      Did you install the Heroku Toolbelt? I believe it comes with foreman. But if not, it’s not a big deal since foreman isn’t required for anything. It just makes local testing a bit easier.

  • ErinM

    I’m trying to use Heroku to create a Facebook app– I installed the toolbelt but am running into lots of problems using Terminal and with Heroku in general. Is there a way to uninstall Heroku from Terminal so I can start over?

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

      I think you can just drag the app from your application folder to the trash. But I’m not totally sure since I don’t use a Mac.

  • Marina Boulding, UK

    I have happily been playing Scrabble excluding US and Can with a neighbour, and suddenly for the last week I cant get in anymore, either from my facebook page or any other way: I get the message:

    Heroku / No such app
    There is no app configured at that hostname. Perhaps the app owner has renamed it or you mistyped the URL

    I am not particularly computer savvy, I was just really enjoying my Scrabble matches and want to be able to do it again – any help you can give me?

    Marina

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

      Sorry Marina. You’ll have to contact the app author about that. Make sure you have the latest version installed.

  • yassinovic

    Hi James,

    I can’t create a new Play app, when when i run the command “play new
    play_hello_world” i get an error message : /usr/bin/env: python: No
    such file or directory

    can you please help me

    thanks

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

      You need to have Python installed on your system for Play 1.

      • yassinovic

        Thakns James, do i need to install Python on heroku ?

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

          Nope. It’s already there.

  • sarfaraz

    after running heroku in cmd.exe its disappear

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

      That is odd. Can you file a support request with Heroku?

  • Amol Chavan

    I have deployed my play app on heroku. It uses heroku DB.

    I followed steps mentioned in http://www.playframework.com/documentation/2.2.x/ProductionHeroku .

    After deployment I am getting

    Application Error.

    Following is the log:

    2013-09-16T12:49:16+00:00 heroku[slug-compiler]: Slug compilation finished
    2013-09-16T12:49:25.869478+00:00 heroku[web.1]: Starting process with command `b
    in/MyfirstDemoPlay -Dhttp.port=${PORT} ${JAVA_OPTS} -DapplyEvolutions.default=tr
    ue -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=${DATABASE_URL}`
    2013-09-16T12:49:26.925988+00:00 app[web.1]: bash: bin/MyfirstDemoPlay: No such
    file or directory
    2013-09-16T12:49:29.702060+00:00 heroku[web.1]: Process exited with status 127
    2013-09-16T12:49:29.717538+00:00 heroku[web.1]: State changed from starting to crashed
    2013-09-16T12:49:54.629536+00:00 heroku[router]: at=error code=H10 desc=”App cra
    shed” method=GET path=/ host=frozen-garden-3696.herokuapp.com fwd=”116.74.208.34
    ” dyno= connect= service= status=503 bytes=
    2013-09-16T12:49:55.048234+00:00 heroku[router]: at=error code=H10 desc=”App cra
    shed” method=GET path=/favicon.ico host=frozen-garden-3696.herokuapp.com fwd=”11
    6.74.208.34″ dyno= connect= service= status=503 bytes=
    2013-09-16T12:56:31.919766+00:00 heroku[router]: at=error code=H10 desc=”App cra
    shed” method=GET path=/ host=frozen-garden-3696.herokuapp.com fwd=”116.74.208.34
    ” dyno= connect= service= status=503 bytes=
    2013-09-16T12:56:32.350463+00:00 heroku[router]: at=error code=H10 desc=”App cra
    shed” method=GET path=/favicon.ico host=frozen-garden-3696.herokuapp.com fwd=”11
    6.74.208.34″ dyno= connect= service= status=503 bytes=
    2013-09-16T12:56:43.256188+00:00 heroku[router]: at=error code=H10 desc=”App cra
    shed” method=GET path=/ host=frozen-garden-3696.herokuapp.com fwd=”116.74.208.34
    ” dyno= connect= service= status=503 bytes=

    can you please tell me what is wrong with this?

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

      What does your `Procfile` look like?

      • Amol Chavan

        I first tried with : web: bin/myapp -Dhttp.port=${PORT} ${JAVA_OPTS} -DapplyEvolutions.default=true -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=${DATABASE_URL}

        And then: web: target/start -Dhttp.port=${PORT} -DapplyEvolutions.default=true -Ddb.default.url=${DATABASE_URL} -Ddb.default.driver=org.postgresql.Driver

        no success in both the case.

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

          If you do a “play stage” then you can generate locally the files that are on Heroku. Then you can verify your Procfile command locally.

          • Amol Chavan

            Pls guide verify your Procfile command locally.

            Thanks

          • Amol Chavan

            I did “stage” then “start” but when i called localhost:9000 from browser following error shown in play console:

            Error occurred during initialization of VM
            java.lang.ExceptionInInitializerError
            at java.lang.Runtime.loadLibrary0(Unknown Source)
            at java.lang.System.loadLibrary(Unknown Source)
            at java.lang.System.initializeSystemClass(Unknown Source)
            Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range:0
            at java.lang.String.charAt(Unknown Source)
            at java.io.Win32FileSystem.(Unknown Source)
            at java.io.WinNTFileSystem.(Unknown Source)
            at java.io.FileSystem.getFileSystem(Native Method)
            at java.io.File.(Unknown Source)
            at java.lang.Runtime.loadLibrary0(Unknown Source)
            at java.lang.System.loadLibrary(Unknown Source)
            at java.lang.System.initializeSystemClass(Unknown Source)

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

            What version of Play?

          • Amol Chavan

            Play 2.1.3

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

            The start script doesn’t work on Windows. :(

            So it seems that the following Procfile should work:
            web: target/start -Dhttp.port=${PORT} -DapplyEvolutions.default=true -Ddb.default.url=${DATABASE_URL} -Ddb.default.driver=org.postgresql.Driver

            Maybe it would help to check out the instructions here: https://github.com/jamesward/play2torial/blob/master/JAVA.md And see if there is a step you missed.

          • Amol Chavan

            Hi,
            The issue was with 1.sql file. I was using mysql on my machine and the generated sql file was for mysql not for postgresql.

            Thanks for your help.

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

            You should use the same database on both systems.



  • View James Ward's profile on LinkedIn