2013-07-16 30 views

回答

-1

您将需要嵌入Groovy解释在您的测试代码:

// call groovy expressions from Java code 
Binding binding = new Binding(); 
binding.setVariable("foo", new Integer(2)); 
GroovyShell shell = new GroovyShell(binding); 

Object value = shell.evaluate("println 'Hello World!'; x = 123; return foo * 10"); 
assert value.equals(new Integer(20)); 
assert binding.getVariable("x").equals(new Integer(123)); 

documentation how to embed Groovy的细节

+0

进口groovy.lang.GroovyClassLoader; import groovy.lang.GroovyObject; import java.io.File; 公共类测试{ \t \t \t公共静态无效主要(字符串ARGS [])抛出的Throwable { \t \t \t 父类加载器= Test.class.getClassLoader(); GroovyClassLoader loader = new GroovyClassLoader(parent); GroovyClassLoader(parent); GroovyClassLoader(parent); GroovyClassLoader \t class groovyClass = loader.parseClass(new File(“src/main/resources/scripts/test.groovy”)); \t //让我们在实例上调用某种方法 \t GroovyObject groovyObject =(GroovyObject)groovyClass.newInstance(); \t Object [] arg = {“cvgf”,“xxx”}; \t groovyObject.invokeMethod(“run”,arg); \t} } –

+0

我得到以下错误: 异常线程 “main” org.codehaus.groovy.control.MultipleCompilationErrorsException:启动失败: 无法解决类的SOAPClient \t高清客户端=新的SOAPClient(URL) ^ –

相关问题