Ale*_*nov 6 eclipse scripting groovy jsr223
我有一个Groovy脚本,运行方式如下:
File scriptFile = ...;
ScriptEngine engine = ...;
String script = FileUtils.readFileToString(scriptFile);
Object evalResult = engine.eval(script, bindings);
Run Code Online (Sandbox Code Playgroud)
不出所料,脚本文件中设置的断点不会触发.我可以改变什么来使它工作?该脚本需要在较大程序(没有单独的启动配置)的上下文中运行,并且通过a运行ScriptEngine,并且该文件仅在运行时已知.
我正在使用这个 hack:我定义了一个 Java 类Debugger,如下所示:
public class Debugger {
private static final Logger log = LoggerFactory.getLogger( Debugger.class );
/**
* Invoke this method anywhere to end up in the Java debugger.
*
* <p>Sometimes, you have code that might eventually be executed or you have a place
* where you want to stop but no code line.
*
* <p>In these case, use this method.
*
* <p>Don't forget to set a breakpoint, first :-)
* */
public static void stopInDebugger() {
log.error( "Please set a breakpoint in Debugger.stopInDebugger() and try again whatever you just did!" );
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个断点log.error。
现在,我可以将此行放入脚本中想要断点的位置:
Debugger.stopInDebugger();
Run Code Online (Sandbox Code Playgroud)
当然,它不允许我轻松地单步执行脚本,但总比没有好。