I was starting with Akka project with SBT but found that the latest SBT is quite different from before.
I tried to create AKKA project with latest SBT but got stuck. Old SBT used to ask to create a new project in case it did not find any in the directory. With new SBT it is not the case. If you want to know how to go about creating new Akka project with SBT read on.
After installing SBT if we type in sbt in the command prompt in an empty directory, this is what we are likely to see.
In order to create project execute the following commands in the sbt session.
We should get the following output if we type the above mentioned commands in sbt session.
SBT creates files and directories when we executed the commands. It creates build.sbt and it contains the same values we typed in sbt session. Other directories like target and project are of little consequence to us.
Project directory will become important later when we will try to add sbteclipse plugin. My project directory contains the following subdirectories and files.
This is how my my build.sbt files looks like after executing the commands in sbt session
One thing that has also changed from the past is that the src directories are not created by default. I used the sbteclipse plugin to do it for me.
Create directory plugins inside project and add build.sbt to it. Add following contents to it:
Execute the following command.
It creates common source directories like src/main/scala, src/main/test, etc and also eclipse project files.
The project is ready to imported in Eclipse IDE. We also require Akka dependencies in our project. This can be done by adding resolvers and library dependencies to build.sbt at the top level. Add the following entries in build.sbt:
Whenever we add new dependencies we must execute “sbt eclipse” to regenerate the eclipse project configuration files. Now in order that code for Akka in our projects compiles correctly in Eclipse we execute the following command:
We have a skeleton project with all dependencies and build scripts ready for an AKKA project. Lets create a simple Echo Akka Actor to validate that our configurations work correctly.
The object Application starts EchoActor passes message to it and then stops it. EchoActor prints the message received from Application.
If all is fine the code will compile without any issues but before we run this Application as scala application we need to download Akka from here and set AKKA_HOME in PATH variable.
After AKKA_HOME points to the right directory we can run the application either from Eclipse or from SBT. For Eclipse run it as Scala Application. For SBT use the command provided below. You should see the “Hello Akka Echo Actor” message in the console.
That is all we need for creating Akka project using the latest SBT. We now know how to create an Akka project using SBT and also to add dependencies to it. We can also generate Eclipse IDE specific project files using sbteclipse.
I have created a sample project AkkaExperiments which has the code for starting Akka project using SBT.
2 thoughts on “Starting Akka Project With SBT 0.104 min read”
For your resolver, I think you should use
resolvers += “Akka Repository” at “http://akka.io/repository”
resolvers += “Typesafe Repository” at “http://repo.typesafe.com/typesafe/releases/”
however both work.
Sounds good. Thanks for the feedback. I see that your company too is working on Scala in HK. Good to be connected. Send me a ping whenever you feel that we can work together. Regards | Vikas
Comments are closed.