xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40">
I write a very simple testing class to test embedding
groovy in java like this. It works very well when I use jdk 1.4.x. But when I
use jdk 1.5 (beta), exceptions are thrown.
My application needs some new feature in jdk 1.5. and
I want to use groovy in this application to do some simple task, just like to
run this script: “result=(data===event.getdate()) “, I will set
data and event in my java code, and bind these variables to groovy shell (these
variables’ type is very simple, does not use 1.5’s new feature, these types can be compiled
in 1.4. In another word, all classes interact with groovy can be compiled in
1.4, these classes only return some primary type variables to classes which
need 1.5), after run this script, I want read the “result” in my
java code. I know how to implement this when use jdk 1.4.x, but how can I make
groovy’s peace with jdk1.5.
Thanks.
public class Main {
public static void main(String[]
arg) {
Binding
binding = new Binding();
binding.setVariable("foo", new Integer(2));
GroovyShell
shell = new GroovyShell(binding);
Object
value=null;
try {
value = shell.evaluate("println 'Hello World!'; x = 123; return foo *
10");
}catch(Exception e){
e.printStackTrace();
}
System.out.println("value = " + value);
System.out.println("binding = " + binding);
//assert
value.equals(new Integer(20));
//assert
binding.getVariable("x").equals(new Integer(123))
}
}
java.lang.ClassFormatError: Illegal method name
"access+000"
at
java.lang.ClassLoader.defineClass1(Native Method)
at
java.lang.ClassLoader.defineClass(ClassLoader.java:604)
at
java.lang.ClassLoader.defineClass(ClassLoader.java:448)
at
groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:266)
at
groovy.lang.MetaClassRegistry.loadClass(MetaClassRegistry.java:122)
at
groovy.lang.MetaClass.loadReflectorClass(MetaClass.java:1451)
at
groovy.lang.MetaClass.loadReflector(MetaClass.java:1437)
at
groovy.lang.MetaClass.generateReflector(MetaClass.java:1390)
at
groovy.lang.MetaClass.checkInitialised(MetaClass.java:1343)
at
groovy.lang.MetaClassRegistry.checkInitialised(MetaClassRegistry.java:139)
at
groovy.lang.MetaClassRegistry.<init>(MetaClassRegistry.java:84)
at
groovy.lang.MetaClassRegistry.<init>(MetaClassRegistry.java:72)
at
org.codehaus.groovy.runtime.Invoker.<init>(Invoker.java:83)
at
org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:82)
at
groovy.lang.GroovyObjectSupport.<init>(GroovyObjectSupport.java:61)
at
groovy.lang.Binding.<init>(Binding.java:62)
at
Main.main(Main.java:14)
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:494)
at
com.intellij.rt.execution.application.AppMain.main(Unknown Source)