So, my problem is the following:
Lets say, i have a base of js modules which need to be preloaded. I have now several scripts which need to be able to be run without interfereing into others.
The scripts look like this:
function A(){
}
function B(){
}
What i want to do is call Function A from Script 1 and Function A from Script 2. But only the last Script is executed correctly since it is the same ScriptEngine I am calling.
I tried an attempt like this:
public static ScriptEngine eval(BufferedReader file) throws ScriptException {
SimpleScriptContext context = new SimpleScriptContext();
context.getBindings(ScriptContext.ENGINE_SCOPE).putAll(engine.getBindings(ScriptContext.ENGINE_SCOPE));
ScriptEngine dengine = new NashornScriptEngineFactory().getScriptEngine("-strict");
dengine.eval(file,context);
ClassLoader cl = MyClass.getInstance().getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(cl);
return dengine;
}
to create multiple ScriptEngines. But that failed. So what is the right attempt, to "clone" already loaded Scripts without rerunning them?