Skip to content

Instantly share code, notes, and snippets.

@tmtk75
Created January 27, 2013 13:32
Show Gist options
  • Save tmtk75/4648348 to your computer and use it in GitHub Desktop.
Save tmtk75/4648348 to your computer and use it in GitHub Desktop.
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