Getting Started with Scala on Heroku

Over the past year I’ve been gradually learning Scala and I think it’s fantastic! So I’m incredibly excited that Scala now runs on Heroku! Of course you can use the standard Java on Heroku / Maven method of running Scala on Heroku. But as of today you can also use sbt (the Scala Build Tool) to run Scala apps on Heroku. If you are new to Heroku, it is a Polyglot Cloud Application Platform. Put very simply:

Heroku = Polyglot + Platform as a Service (PaaS) + Cloud Components

If you want to try out Scala on Heroku, here are a few quick steps to get you started:

  1. Create a Heroku account
  2. Install the Heroku command line client on Linux, Mac, or Windows.
  3. Install git and setup your SSH key
  4. Install sbt 0.11.0
  5. Login to Heroku from the command line:

    heroku auth:login
  6. Create a file named build.sbt containing:
    scalaVersion := "2.9.1"
      val stage = TaskKey[Unit]("stage", "Prepares the project to be run, in environments that deploy source trees rather than packages.")
      stage in Compile := {}

    This adds the “stage” task which is used for the build on Heroku.

  7. Create a project/ file containing:

    This tells sbt which version of sbt to use.

  8. Create a very simple Scala app in src/main/scala/Hello.scala containing:
    object Hello extends App {
      println("hello, world")
  9. Test the app locally by running:
    sbt run

    You should see something like:

    [info] Set current project to default-0c17d0 (in build file:/home/jamesw/projects/helloscala/)
    [info] Running Hello 
    hello, world
    [success] Total time: 1 s, completed Sep 7, 2011 4:17:01 AM
  10. Create a .gitignore file containing:
  11. Create a git repo, add the files to it, and commit them:
    git init
    git add .
    git commit -m init
  12. Create a new app on Heroku using the Cedar stack:
    heroku create -s cedar
  13. Upload your app to Heroku using git:
    git push heroku master
  14. Run the app on Heroku:
    heroku run "sbt run"

    VoilĂ ! You just ran Scala on the Cloud!

You can get the full code for this project on github:

That was a very simple example to get you started. Visit the Heroku Dev Center to continue learning about how to use Scala on Heroku. And let me know if you have any questions.