【发布时间】:2018-11-18 07:08:13
【问题描述】:
我花了很多时间寻找答案。我找到了类似here 的解决方案,但它是错误的。这对我不起作用。
情况:
我有 2 个 groovy 脚本和 java 应用程序。
Another.groovy(自动测试/来源)
class Another
{
protected String name="";
public Another() {}
public main(String[] args) {}
public boolean getResult() {return true;}
public String getName() {return name;}
public void setName(String value) {name=value;}
}
test.groovy(自动测试/案例)
evaluate(new File("autotest/sources/Another.groovy"))
import support.tool.AutotestResult;
public class Another2 extends Another
{
public Another2()
{
this.setName(this.name+"N");
}
public AutotestResult run()
{
return new AutotestResult(this.name+"123",this.getResult(),null,null)
}
}
Another2 a = new Another2()
a.run()
名为“test.groovy”的 Java 类
String[] paths = {"autotest\\cases\\test.groovy"};
GroovyScriptEngine gse = new GroovyScriptEngine(paths);
Binding binding = new Binding();
binding.setVariable("args",null);
System.out.println(((AutotestResult)gse.run("test.groovy", binding)).toJSON());
如果 Another.groovy 和 test.groovy 在同一个文件夹中,它会完美运行。但如果 Another.groovy 在另一个文件夹中,它就不起作用。 Java返回错误:
Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/.../autotest/cases/test.groovy: 6: unable to resolve class Another
@ line 6, column 1.
public class Another2 extends Another
^
所以我有问题:
- 可以提供一些建议吗?
- 有可能吗(一个脚本的类扩展了另一个脚本的类)?
- 还有其他方法吗?
PS。抱歉英语不好。
【问题讨论】: