sbt Basics

sbt (Scala Build Tool) is the standard build tool for Scala development, and we will be using it this semester. It is installed on the lab machines and you can run it by simply executing sbt. This will put you on a prompt that is somewhat similar to a REPL where you can type in various commands. I'm listing here the main commands that you will likely use this semester.

    • compile - This compiles the code in src/main and tells you about any errors.

    • test:compile - This compiles the code in src/test and tells you about any errors.

    • console - This runs a Scala REPL in the project so you have access to any libraries or code that is part of the project.

    • doc - This runs scaladoc and generates documentation for the project.

    • run - This looks for any executable objects and gives you the option for which one to run.

    • runMain <object> - Lets you run a particular executable object directly.

    • test - Runs all the tests that are found in the src/test directory.

    • assembly - This builds a "fat JAR" that has all the compiled code and resources in it so that other people can run it.

For a more complete list of commands see the configuration-level tasks here.

Note that sbt has a specific directory structure that specifies where things are placed. (This is actually the same directory structure as the Maven build tool for Java.) The projects that I set up for you have this structure already in place. You just need to make sure that when you write code you put it in src/main/scala or src/test/scala depending on whether it is test code or not. I recommend that images

Getting Started with Eclipse

After you clone one of the projects that I have provided for you, you need to do the following things to be able to work with it in Eclipse.

  • Go into the directory where you cloned the project.

  • Run sbt.

  • Run the compile command in sbt.

  • Run the eclipse command in sbt.

  • Exit sbt either by typing exit or hitting Ctrl-D.

  • Start Eclipse by running eclipse on the command line.

  • Go to File > Import... > General > Existing Projects into Workspace

  • Browse to the directory where you cloned the project. When you select it, you should see a project listed. Hit finish.