This is a simple lightweight template for getting started creating Scala projects. It consists of a simple 'Hello World' program and some sample tests.
It uses the Simple Build Tool (SBT) to quickly and easily:
- download all the libraries on which the project depends, including Scala, if necessary
- run your programs and tests
- to generate the necessary configuration files for importing your project into an IDE such as Eclipse or Intellij IDEA
Assuming you have Java 1.5 or later installed, to get started:
Download the template:
git clone git://github.com/dph01/scala-sbt-template.git
Or, if you don't have git installed, download and unzip the files manually from here.
cd scala-sbt-template ./sbt (or sbt.bat for Windows)
This downloads all the dependencies for the project.
To run your program, in SBT:
This searches all objects for a 'main' method. If it finds more than one, it asks you to chose which you want to run.
To load the project into Eclipse, at the SBT prompt:
> eclipse with-sources=true
Then from within Eclipse, select File->Import->General->Existing Projects Into Workspace, and select your project directory. Install the Eclipse Scala IDE plugin from here.
Or, to load the project into Intellij IDEA, at the SBT prompt:
Then from within IDEA, select File -> Open Project, and select your project directory.
Put your Scala class files in src/main/scala. An example has been created in: src/main/scala/com/myapp/App.scala. SBT uses the same folder structure as Maven. For more information see here.
Write your tests in src/test/scala (some examples have been included). To run all your tests:
To run just one test:
> test-only com.myapp.AppTest
To launch the Scala interpreter, at the sbt prompt:
This allows you to 'play around' with Scala commands, with full access to all the libraries defined in your project. Ctrl-D returns you to SBT.
To view / modify project configuration settings, see build.sbt in the project root directory. If you change anything, run
from within SBT for your changes to take effect.
For comments, questions, etc. please see the accompanying blogpost.