Getting things going took a little bit of setup, perhaps the Akka project can improve this in the future by providing a broader overview of the setup as part of the getting-started tutorial. I have messed around with Scala in the past but I had not yet used tools such as sbt which is a build tool for Scala projects.
The first step was getting sbt installed which was found in the Setup Guide for sbt.
$ cd ~/bin $ wget http://simple-build-tool.googlecode.com/files/sbt-launch-0.7.4.jar $ ln -sv sbt-launch-0.7.4.jar sbt-launch.jar $ echo 'java -Xmx512M -jar `dirname $0`/sbt-launch.jar "$@"' > sbt $ chmod u+x sbt
I downloaded the 1.0-RC1 release of Akka and extracted it to ~/lib/akka
Then I moved to my project dir 'helloakka' and ran sbt to create a project. To prepare the project for Akka I needed to add some sbt plugins.
project/plugins/Plugins.scala
import sbt._
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
val AkkaRepo = "Akka Repository" at "http://scalablesolutions.se/akka/repository"
val akkaPlugin = "se.scalablesolutions.akka" % "akka-sbt-plugin" % "1.0-RC1"
}
project/build/Project.scala
import sbt._
class HelloAkkaProject(info: ProjectInfo) extends DefaultProject(info) with AkkaProject {
val AkkaRepo = "Akka Repository" at "http://scalablesolutions.se/akka/repository"
}
Akka wants a configuration file, even if it is blank it will use the default settings. All of the defaults are listed in the reference config.
$ touch src/main/resources/akka.conf
src/main/scala/helloakka.scala
import akka.actor.Actor
import akka.actor.Actor.actorOf
class HelloWorldActor extends Actor {
def receive = {
case msg => {
println(msg + ", World!")
}
}
}
Now that all of this is in place I can prepare and run it.
$ sbt update $ sbt console
On the console it is possible to manipulate the actor.
scala> import akka.actor.Actor._ scala> val ha = actorOf[HelloWorldActor].start scala> ha ! "Hello"
I have made this outline project available on github.
git clone git://github.com/tcosprojects/helloakka.git
I hope this information is helpful for people trying to get started with Akka. From here I'm going to look at using some of the other features of Akka as well as bundling the program into a standalone program using the Akka microkernel.