gpt4 book ai didi

eclipse - 从 Eclipse 调试在 ScriptEngine 中运行的 Groovy 脚本

转载 作者:行者123 更新时间:2023-12-03 14:40:20 24 4
gpt4 key购买 nike

我有一个像这样运行的 Groovy 脚本:

File scriptFile = ...;
ScriptEngine engine = ...;
String script = FileUtils.readFileToString(scriptFile);
Object evalResult = engine.eval(script, bindings);

不出所料,脚本文件中设置的断点不会触发。我可以改变什么来使它工作?该脚本需要在较大程序的上下文中运行(没有单独的启动配置),并通过 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!" );
}
}

我在 log.error 中有一个断点Ecipse 中的行。

现在,我可以将此行放入我想要断点的脚本中:
Debugger.stopInDebugger();

当然,它不允许我轻松地单步执行脚本,但总比没有好。

关于eclipse - 从 Eclipse 调试在 ScriptEngine 中运行的 Groovy 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11758688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com