anu*_*ava 55
基本Java + 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(groovyScript);
Run Code Online (Sandbox Code Playgroud)
PS:您需要包含groovy-all-m.n.m.jar
例如groovy-all-2.1.6.jar
Java程序,例如:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.8</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)