使用 GroovyShell 加载的调试脚本(在 Eclipse 中) [英] Debugging scripts loaded with GroovyShell (in eclipse)

查看:47
本文介绍了使用 GroovyShell 加载的调试脚本(在 Eclipse 中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Eclipse 和 groovy 插件.我正在构建一个测试工具来调试和测试 groovy 脚本.脚本非常简单但很长,其中大部分只是 if/else/return.我发现我可以使用 GroovyShell 和 Bindings 调用它们来传递值.

I am working with eclipse and groovy plug in. I am building a test harness to debug and test groovy scripts. The scripts are really simple but long, most of them just if/else/return. I figured out that I can call them using GroovyShell and Bindings to pass in the values.

问题是,虽然我可以调用脚本并获得很好的结果,但我无法使用调试器介入.这些脚本中的断点未激活.

The problem is that, while I can call the script and get the results just fine, I CAN NOT step in there with the debugger. Breakpoints in those scripts are not active.

有没有办法调试脚本?也许我应该使用 GroovyShell 以外的其他东西?我真的不想通过将脚本包装到函数中来修改脚本,然后从我的测试类中调用这些函数.

Is there a way to debug the scripts? Maybe I should use something other than GroovyShell? I really don't want to modify the scripts by wrapping them into functions, and then calling those functions from my test classes.

这就是我使用 Binding 和 GroovyShell 的方式:

That's how I am using Binding and GroovyShell:

            def binding = new Binding();
            binding.lineList = [list1];
            binding.count = 5;

            def shell = new GroovyShell(binding);
            def result = shell.evaluate(new File("src/Rules/checkLimit.groovy"));

推荐答案

我猜你的脚本不在你项目的类路径中.您需要将它们添加到类路径中,最好确保包语句正确(或确保它们位于该源文件夹的默认目录中).

I am guessing that your scripts are not on the classpath of your project. You need to add them to the classpath and preferably make sure that package statements are correct (or make sure they are in the default directory for that source folder).

您可能还想将此源文件夹指定为脚本文件夹.这将确保您的脚本不会被编译到输出文件夹中.您可以通过 Preferences -> Groovy -> Compiler 执行此操作.单击复选框以启用脚本文件夹,然后创建正则表达式以指定文件夹.您还可以指定是否应按原样将脚本复制到输出文件夹.

You may also want to designate this source folder as a script folder. This will ensure that your scripts are not compiled to the output folder. You can do this through Preferences -> Groovy -> Compiler. Click the checkbox to enable script folders and then create the regex to specify the folder. You can also specify whether or not the scripts should be copied over as-is to the output folder.

这篇关于使用 GroovyShell 加载的调试脚本(在 Eclipse 中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆