我正在尝试将Groovy与JSR223一起使用。我有一个groovy脚本文件,在程序启动时进行评估。
知道可能出现什么问题吗?我正在使用JDK 6和groovy-all-2.3.0.jar
Exception in thread "main" java.lang.NoSuchMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.GetObjectName() is applicable for argument types: (java.lang.String, java.lang.String) values: [param1, param2]
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.invokeImpl(GroovyScriptEngineImpl.java:396)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.invokeFunction(GroovyScriptEngineImpl.java:192)
at GroovyTest.main(GroovyTest.java:61)
Groovy代码:
def GetObjectName(java.lang.String xml, java.lang.String xml2) {
println("xml="+xml);
println("xml2="+xml2);
return "GetObjectName";
}
执行此处调用的Java代码:
...
String dmpExec=null;
engine.getContext().setAttribute("dmp", dmpExec, ScriptContext.ENGINE_SCOPE);
engine.eval(fileContents2.toString());
Invocable inv = (Invocable) engine;
String function="GetObjectName";
System.out.println("function="+function);
Object ret = (Object)inv.invokeFunction(function, "param1", "param2");
...
此处参考完整的Java代码:https://pastebin.com/QaWEDUg3