Created
January 27, 2013 13:32
-
-
Save tmtk75/4648348 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.script.*; | |
public class GroovyScripting { | |
public static void main(String[] args) throws Exception { | |
ScriptEngine engine = new ScriptEngineManager().getEngineByName("groovy"); | |
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); | |
bindings.put("counter", 0); | |
bindings.put("args", new String[] {"hello", "world"}); | |
String LF = "\n"; | |
String code = "" | |
+ "counter += 1" + LF | |
+ "println args[0]" + LF | |
+ "true" | |
; | |
System.out.println(engine.eval(code)); | |
System.out.println(bindings.get("counter")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment