Reputation: 4960
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
Upvotes: 6
Views: 924
Reputation: 8932
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
).
Upvotes: 4