Build with SBT

Here, we are going to give a brief introduction to SBT. Before going any further, you need to install SBT using the installation method that fits your system from their official installations methods (URL: http://www.scala-sbt.org/release/docs/Setup.html).

So, let's begin with SBT to demonstrate the use of SBT in a terminal. For this build tool tutorial, we assume that your source code files are in a directory. You need to do the following:

  1. Open the terminal and change path to that directory by using cd,
  2. Create a build file called build.sbt.
  3. Then, populate that build file with the following lines:
           name := "projectname-sbt"
organization :="org.example"
scalaVersion :="2.11.8"
version := "0.0.1-SNAPSHOT"

Let's see the meaning of these lines:

  • The name defines a name for your project. This name will be used in the generated jar files.
  • The organization is a namespace that's used to prevent collisions between projects that have similar names.
  • scalaVersion sets the version of Scala that you want to build against.
  • Version specifies the current build version of your project and you can use -SNAPSHOT for versions that have not been released yet.

After creating this build file, you need to run the sbt command in your terminal and then a prompt starting with > will be opened for you. In this prompt, you can type compile in order to compile your Scala or Java source files in your code. Also, you can enter the command in the SBT prompt in order to run the program if it's runnable. Or you can use the package command in SBT prompt in order to generate a .jar file, which will exist in a subdirectory called target. To read more about SBT and more sophisticated examples, you can refer to the official site of SBT.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.147.20