Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to develop with akka and sbt?

Tags:

scala

akka

sbt

Developing with sbt I hardly use ~run command, to say sbt pickup my code changes. This is very comfortable.

Now I am going to play a bit with akka. Is there any way to bring back default sbt's behaviour, when ctrl+D stops application, and code picked up on the fly?

Here is sample app:

object Main extends App {
  println("Starting actors...")
  val system = ActorSystem("MySystem")
  val myActor = system.actorOf(Props[Actors.MyActor], name = "myActor")
  myActor ! "test"
  // system.shutdown()
}

object Actors {
  class MyActor extends Actor {
  val log = Logging(context.system, this)
  def receive = {
    case "test" => log.info("received test")
    case _      => log.info("received something else")
  }
}

}

In such case run and ~run commands nor interrupting by ctrl+D nor reloading code on change. Only ctrl+C to stop whole sbt. As I understand play framework have some solution for doing this, because looks like it stopping actor system on ctrl+D in ~run mode

like image 713
Alex Povar Avatar asked Jun 23 '13 07:06

Alex Povar


People also ask

How do I start an Akka project?

The simplest way to get started with Akka and Maven is to check out the Lightbend Activator tutorial named Akka Main in Java. Since Akka is published to Maven Central (for versions since 2.1-M2), it is enough to add the Akka dependencies to the POM. For example, here is the dependency for akka-actor: <dependency>

Can sbt build Java?

sbt has support for compiling Java sources with the limitation that dependency tracking is limited to the dependencies present in compiled class files.

Is Akka a programming language?

Akka is a free and open-source toolkit and runtime simplifying the construction of concurrent and distributed applications on the JVM. Akka supports multiple programming models for concurrency, but it emphasizes actor-based concurrency, with inspiration drawn from Erlang.


1 Answers

You could try JRebel. You can get a free license for Scala development. Worked for me very fine, especially together with sbt. Sbt compiles the classes, the running Scala application with JRebel loads the newly compiled classes on the fly in the running app, without restart.

My build.sbt has the following entries:

javaOptions ++=Seq("-javaagent:/path/to/jrebel.jar","-Drebel.log=true","-Drebel.log.file=/path/to/jrebel.log")

fork := true

I have two sbt instances running. One runs the program, the other one compiles all classes when a change is detected (~compile).

like image 138
stefan.schwetschke Avatar answered Oct 28 '22 01:10

stefan.schwetschke