Dashboard
>
Public Content
>
...
Home
>
JavaStuff
>
Run a Groovy Script
Public Content
Log In
Run a Groovy Script
Browse Space
View
I
nfo
Added by
James Richardson
, last edited by
James Richardson
on Mar 18, 2008
Labels:
(None)
Add Labels
Enter labels to add to this page:
Tip:
Looking for a label? Just start typing.
private static void invokeScript(String scriptName, Map<String, Object> variables) throws ScriptException, ResourceException, IOException { URL location = Demo.class.getProtectionDomain().getCodeSource().getLocation(); String packagesDirectory = Demo.class.getPackage().getName().replaceAll("\\.", "/"); GroovyScriptEngine gse = new GroovyScriptEngine(new URL[]{new URL(location, packagesDirectory + "/")}); Binding binding = new Binding(); for (String variableName : variables.keySet()) { binding.setVariable(variableName, variables.get(variableName)); } gse.run(scriptName, binding); // System.out.println(binding.getVariable("output")); }
Add Comment
Powered by
Atlassian Confluence
, the
Enterprise Wiki
. (Version: 2.5.1 Build:#806 May 06, 2007) -
Bug/feature request
-
Contact Administrators