hello world with Scala and sbt

Preamble

I’d like to learn more about Scala.  To get started, I’m going to run through a hello world example on sbt’s Google Code site.  Here are my system details:

  • Mac 10.6.6
  • Scala 2.7.7
  • sbt 0.7.4
  • Java 1.6

Steps

  1. Create a new sbt project by simply running the command sbt.  I set the name to “hw”, the organization to “foo.com”, and the project version to “1.0”, and accepted the defaults for the Scala and sbt versions but just hitting enter.  After building the project, sbt will leave a command prompt open.  Close this by typing ctrl-D.  Note: The quick start creates the code first, but then doesn’t talk about where to put it, which I found a bit confusing, so I’m presenting it here in reverse order.

    Screen shot of sbt creating a project
    Screen shot of sbt creating a project
  2. Create the file hw.scala in the src/main/scala/ directory generated by sbt:
    echo ‘object Hi { def main(args: Array[String]) { println(“Hi!”) } }’ > src/main/scala/hw.scala
  3. Compile the project: sbt compile

    Screen shot of compiling a project
    Screen shot of compiling a project
  4. Run the project: sbt run

    Screen shot of running a project
    Screen shot of running a project

Conclusion

So that’s that. It’s just hello world, but I found it helpful as an introduction to sbt’s relationship to Scala.  Time to call it a day, like these birds are doing:

birds on a wire
"birds on a wire" by touterse