One of my biggest gripes with Java (and all the languages that run on the JVM) is getting my project setup and building it. Maven is not my favorite, and ant..well..I don't like it either. Fortunately, if you want to start a new project in Scala, there is a great build tool available that takes a lot of the pain out of project management and building - SBT, simple-build-tool.
sbt is a simple build tool for Scala projects that aims to do the basics well. It requires Java 1.5 or later.
I'm using Mac OS X, but the following instructions should be pretty much the same on any Unix based OS.
You can find the latest version of SBT here.
This will install the SBT jar and create a script called sbt that will allow you to run the sbt jar.
Just type sbt and press enter, and you now have access to sbt.
Creating a new Scala project
Now we will create a Hello World Scala project with SBT.
Running the sbt command in a directory where there is no project will prompt you to create one.
Awesome. It handles all the Scala dependencies for us! Now let's create a file that contains our Hello, Scala example.
Below is the directory structure of an SBT project.
Creating our HelloScala sources and running
Now we are going to create our main file, HelloScala.scala
And now we can build and run it by just issuing the following:
And the output:
And that's it. Setting up a new Scala project with SBT is painless. In the next part I will talk about managing dependencies and how SBT makes this also very easy.
You can read a lot more about SBT by checking out their wiki.
Update 09/18/2011 - If you are on a Mac, its probably easier to install sbt this way:
The above command requires homebrew, a package manager for OS X. Get it here: https://github.com/mxcl/homebrew