Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code> class testScriptEngine { private final Map&lt;String, CompiledScript&gt; compiledScripts = new HashMap&lt;String, CompiledScript&gt;(); GroovyClassLoader gcl = new GroovyClassLoader(); ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("groovy"); GroovyCompiledScript compilescript(ScriptEngine engine, String scriptName) { GroovyScriptEngineImpl groovyEngineImpl = (GroovyScriptEngineImpl) engine; gcl = groovyEngineImpl.getClassLoader(); Class&lt;?&gt; scriptClass = null; try { scriptClass = gcl.parseClass(new File(scriptName)); GroovyCompiledScript compiledScript = new GroovyCompiledScript( groovyEngineImpl, scriptClass); return compiledScript; } catch (MultipleCompilationErrorsException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (CompilationFailedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } public void run() { // System.out.println(compiledScripts); System.out.println(engine instanceof GroovyScriptEngineImpl); Bindings bindings = engine.createBindings(); bindings.putAll(engine.getBindings(ScriptContext.ENGINE_SCOPE)); String fileName = "script1.groovy"; CompiledScript compiledScript = compiledScripts.get(fileName); try { compiledScript.eval(bindings); } catch (ScriptException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private void compileScript() { String fileName = "Script1.groovy"; compiledScripts.put(fileName, compilescript(engine, fileName)); fileName = "Script2.groovy"; compiledScripts.put(fileName, compilescript(engine, fileName)); fileName = "Script3.groovy"; compiledScripts.put(fileName, compilescript(engine, fileName)); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload