2013-07-16 50 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) ^ –

相關問題