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
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>
sbt has support for compiling Java sources with the limitation that dependency tracking is limited to the dependencies present in compiled class files.
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.
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With