Scala sbt console - code changes not reflected in sbt console
Asked Answered
A

2

42

I use scala sbt console to test my methods. (commands : sbt then console) But the code changes done in eclipse or other external editor, are not getting reflected in the sbt console.

Every time, I have to quit the console (using Crt + D) and again start it using console command to see the changes.

Any one facing this problem? Is there any ways to reload the code from console?

I am using Ubuntu 64-Bit,

Audrieaudris answered 3/10, 2012 at 7:11 Comment(0)
I
35

Not without using something like JRebel, mostly because class definitions could break in such a way as to make instances already loaded unusable. The only suggestion I have is to run the console with ~console so that if changes have been made they will be recompiled and the console re-entered.

Also if you're regularly running a set of commands the initialCommands sbt setting configures commands to be run immediately after starting the console.

Illfated answered 3/10, 2012 at 7:40 Comment(2)
using sbt 0.13 the console does not restart automatically. Even more weird, then I get out of the console using exit, it recompiles and re-enters the console.Limekiln
Adding the tilde just runs any command when the source code changes, but in the case of "console" it's still running until you exit it.Illfated
C
20

One option is to use :restart in the console - this will reload it and replay all the commands you've entered so far.

For a better solution you might want to read my blog post on incremental development with JRebel & Scala.

You should modify the sbt startup script like this:

#!/bin/bash

java -noverify -javaagent:/home/username/path/to/jrebel/jrebel/jrebel.jar
 -Drebel.lift_plugin=true -XX:+CMSClassUnloadingEnabled
 -XX:MaxPermSize=512m -Xmx512M -Xss2M -jar `dirname $0`/sbt-launch.jar
 "$@"

When you start the REPL from inside SBT, for instance with the command:

sbt console

changes to the imported classes will be reflected automatically without the need to do a :replay or restart the REPL - something reminiscent of the interactive Lisp programming.

Craft answered 3/10, 2012 at 11:24 Comment(5)
Thanks, This also helps. But we dont use jrebel now.Audrieaudris
Since it's free for Scala development you might consider it.Craft
Note that blog post requires a Maven continuous compile going in the background. If you're not using Maven, you can just open a second SBT process with an SBT continuous compile: ~; compile.Glendoraglendower
Rather than modify the startup script, you might export SBT_OPTS from your global SBT config file at ~/.sbtconfigStopwatch
No :restart command on vanilla sbt. Does this require JRebel or something?Ji

© 2022 - 2024 — McMap. All rights reserved.