Scala sbt 控制台 - 代码更改未反映在 sbt 控制台中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12703535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Scala sbt console - code changes not reflected in sbt console
提问by C.Karthik
I use scala sbt console to test my methods. (commands : sbtthen console) But the code changes done in eclipse or other external editor, are not getting reflected in the sbt console.
我使用 scala sbt 控制台来测试我的方法。(命令:sbt然后控制台)但是在 eclipse 或其他外部编辑器中完成的代码更改没有反映在 sbt 控制台中。
Every time, I have to quit the console (using Crt + D) and again start it using consolecommand to see the changes.
每次,我都必须退出控制台(使用 Crt + D)并再次使用控制台命令启动它以查看更改。
Any one facing this problem? Is there any ways to reload the code from console?
有人面临这个问题吗?有没有办法从控制台重新加载代码?
I am using Ubuntu 64-Bit,
我使用的是 64 位 Ubuntu,
采纳答案by Sean Parsons
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 ~consoleso that if changes have been made they will be recompiled and the console re-entered.
不是不使用 JRebel 之类的东西,主要是因为类定义可能会以某种方式中断,从而使已加载的实例无法使用。我唯一的建议是使用~console运行控制台,这样如果进行了更改,它们将被重新编译并重新进入控制台。
Also if you're regularly running a set of commands the initialCommands sbt setting configures commands to be run immediately after starting the console.
此外,如果您定期运行一组命令,initialCommands sbt 设置会将命令配置为在启动控制台后立即运行。
回答by Bozhidar Batsov
One option is to use :restartin the console - this will reload it and replay all the commands you've entered so far.
一种选择是:restart在控制台中使用- 这将重新加载它并重播您迄今为止输入的所有命令。
For a better solution you might want to read my blog poston incremental development with JRebel & Scala.
要获得更好的解决方案,您可能需要阅读我关于使用 JRebel 和 Scala 进行增量开发的博客文章。
You should modify the sbt startup script like this:
您应该像这样修改 sbt 启动脚本:
#!/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 sbt console
`/sbt-launch.jar
"$@"
When you start the REPL from inside SBT, for instance with the command:
当您从 SBT 内部启动 REPL 时,例如使用以下命令:
##代码##changes to the imported classes will be reflected automatically without the need to do a :replayor restartthe REPL - something reminiscent of the interactive Lisp programming.
对导入类的更改将自动反映,无需执行:replay或restartREPL - 这让人联想到交互式 Lisp 编程。

