public final class Scripts extends Object
This is mostly about class loaders. Scripts have at least three class loaders
to worry about. The first is the thread context class loader. The second is
the class loader used by ScriptEngineManager
to find the
implementations of script languages. The third is the class loaders used by
the script engine to find additional classes.
For Rhino this is all pretty straight forward. The class loaders used by the
script is the current thread context class loader. However this was changed
with Nashorn. Here the script has a special class loader, used inside the
script. This can be set using a non-standard API, however the default value
for this class loader is the current thread context class loader during
creation of the ScriptEngine
instance.
Modifier and Type | Method and Description |
---|---|
static ScriptEngine |
createEngine(ScriptEngineManager engineManager,
String engineName,
ClassLoader scriptClassLoader) |
static ScriptEngine |
createEngine(String engineName,
ClassLoader scriptClassLoader) |
static ScriptEngineManager |
createManager(ClassLoader contextClassLoader)
Create a new script engine manager
|
static <V> V |
executeWithClassLoader(ClassLoader classLoader,
Callable<V> callable) |
public static ScriptEngineManager createManager(ClassLoader contextClassLoader)
Note: The context class loader will be set during the creation
of the script engine. However the constructor
ScriptEngineManager.ScriptEngineManager(ClassLoader)
with the
parameter null
will still be used in order to look up the
default script languages of the JRE.
contextClassLoader
- the context class loader to useScriptEngineManager
public static ScriptEngine createEngine(String engineName, ClassLoader scriptClassLoader) throws Exception
Exception
public static ScriptEngine createEngine(ScriptEngineManager engineManager, String engineName, ClassLoader scriptClassLoader) throws Exception
Exception
public static <V> V executeWithClassLoader(ClassLoader classLoader, Callable<V> callable) throws Exception
Exception
Copyright © 2016 Eclipse NeoSCADA Project. All rights reserved.