Assuming that readers are Scala developers, it is obvious they have knowledge of SBT (Simple Build Tool) to build a Scala project.
To step through this recipe, you will need SBT installed on your machine. No other prerequisites are required.
If you don't have SBT installed on your machine, please visit the SBT manual installation page(http://www.scala-sbt.org/release/docs/Manual-Installation.html), and follow the instructions for the operating system you have.
SBT is used for building Scala projects as we have Maven for Java projects. However, both SBT and Maven are capable of building Scala, Java projects.
In this book, we will build our projects on the Ubuntu Linux operating system.
- For creating an SBT project, we need to create a project directory, for example,
Hello-Akka
.
Following screenshot shows the creation of the project directory:
Creating the project directory
- Descend to the directory and run command
sbt
. We will enter into the sbt prompt mode, Now run the following commands one by one, as shown in the next screenshot:
set name := "Hello-Akka" set version := "1.0" set scalaVersion: ="2.11.7" session save exit
This will create a build file called build.sbt
and a target to put your class files into.
- Edit the build file, and add the Akka actor dependency as follows:
libraryDependencies += "com.typesafe.akka" %
"akka-actor_2.11" % "2.4.4"
We can select a specific Akka actor version against a specific Scala version in the maven repository:
Adding Akka dependency to build file
- Run the command
sbt update
; it will download the Akka dependency. Now we have the Akka actor's capabilities in our project, and we are ready to write reactive programs.
The SBT (Simple Build tool), as the name suggests is a widely used tool for building Scala projects.
In step one, we create a project directory where we keep our source files, project build definition, and target, where class files are kept for runtime execution.
In step two, we create a project build definition file, called build.sbt
, by executing simple sbt
command.
In step three, we add a library dependency in the build file for the Akka actor to enable Akka capabilities.
In step four, we download the Akka dependency using the sbt update
command, and our project is now ready for writing Akka-based applications.
This is how we can set up an Akka-based project.