Tuesday, November 27, 2012

Akka in Eclipse on Mac OS

These are my rough notes for getting Akka HEAD going in Eclipse with the Scala plugin. I used a nightly build of the plugin to get support for a recent version of Scala.

  1. Fork the Akka repository.
  2. Make a local clone of your fork.
    git clone git@github.com:richdougherty/akka.git akka
  3. Build it and run tests.
    $ sbt test
  4. Create an ~/.sbt/plugins/plugins.sbt file to teach SBT about the sbteclipse plugin.
    addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")
  5. Generate Eclipse project metadata.
    $ sbt eclipse
  6. Download Eclipse Indigo SR2 and install it somewhere. Do not run it yet.
  7. Find the Eclipse application and view its contents by right-clicking and choosing Show package contents.
  8. Update Contents/MacOS/eclipse.ini according to these instructions. OK, I used a bit more memory. My changes were:
    $ diff -u Eclipse.app/Contents/MacOS/eclipse.ini Eclipse\ retinafied.app/Contents/MacOS/eclipse.ini 
    --- Eclipse.app/Contents/MacOS/eclipse.ini 2012-11-26 13:48:13.000000000 +0100
    +++ Eclipse retinafied.app/Contents/MacOS/eclipse.ini 2012-11-26 14:00:45.000000000 +0100
    @@ -16,9 +16,11 @@
  9. I have a high-res (Retina) screen on my Mac so I enabled high-resolution fonts for the Eclipse application according to these instructions. Update Contents/MacOS/eclipse.ini according to these instructions. If you've already started the application then your changes might not be picked up because of OS caching. Read the linked instructions for a workaround. My changes were:
    $ diff -u Eclipse.app/Contents/Info.plist Eclipse\ retinafied.app/Contents/Info.plist 
    --- Eclipse.app/Contents/Info.plist 2012-11-26 13:34:45.000000000 +0100
    +++ Eclipse retinafied.app/Contents/Info.plist 2012-11-27 11:40:36.000000000 +0100
    @@ -69,9 +69,6 @@
    - <key>NSHighResolutionCapable</key>
    - <true/>
  10. Open Eclipse.
  11. Tell Eclipse how to get the 2.10.x nightly build of the Scala plugin. Go to Help and choose Install New Software…. The update site is located at http://download.scala-ide.org/nightly-update-master-trunk. There are also milestone builds available.
  12. Go to General and Workspace and set the Text file encoding to UTF-8. Otherwise you'll get funny errors when Scala tries to compile the ⇒ characters in Akka source code.
  13. Use Import Existing Projects into Workspace… to pull in the Akka source code.
  14. Done!

Update: Explained how to add Scala plugin. Oops!

Saturday, November 10, 2012

Minimal Akka Hello World with SBT

  1. Create a directory for our project files.
  2. Create helloworld.scala in the project directory.
    import akka.actor._
    import akka.pattern.ask
    import akka.util.duration._
    import akka.util.Timeout
    case class Print(s: String)
    case object PrintAck
    class Printer extends Actor {
      def receive = {
        case Print(s) => {
          sender ! PrintAck
    object HelloWorld {
      def main(args: Array[String]) {
        val system = ActorSystem("HelloWorld")
        val printer = system.actorOf(Props[Printer])
        implicit val timeout = Timeout(5 seconds)
        (printer ? Print("Hello world")) onComplete {
          _ => system.shutdown()
  3. Create build.sbt in the project directory.
    name := "Akka Hello World"
    version := "1.0"
    scalaVersion := "2.9.2"
    resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
    libraryDependencies += "com.typesafe.akka" % "akka-actor" % "2.0.3"
  4. Download the latest SBT launch JAR and install it somewhere. This JAR bootstraps SBT and builds the project. I downloaded the 0.12.1 version. You can get the location of the latest version from the SBT Manual Installation instructions on the SBT website.
  5. Go to your project directory and run SBT. The following has the recommended VM options for running on Windows. Replace XXX with your SBT installation location.
    $ java -Xmx512M -jar XXX/sbt-launch-0.12.1.jar
    [info] Set current project to Akka Hello World (...)
  6. Run the program!
    > run
    [info] Running HelloWorld
    Hello world
    [success] Total time: 6 s, completed 11/11/2012 11:02:21 AM

See also: