public class ScriptUtil extends Object
Constructor and Description |
---|
ScriptUtil() |
Modifier and Type | Method and Description |
---|---|
static CompiledScript |
compile(ScriptEngine engine,
String script)
编译Javascript脚本
|
static CompiledScript |
compile(String script)
编译Javascript脚本
|
static ScriptEngine |
createGroovyEngine()
创建Groovy引擎
需要引入org.codehaus.groovy:groovy-all |
static ScriptEngine |
createJsEngine()
创建新的JavaScript引擎
|
static ScriptEngine |
createLuaEngine()
创建Lua引擎
需要引入org.luaj:luaj-jse |
static ScriptEngine |
createPythonEngine()
创建Python引擎
需要引入org.python:jython |
static ScriptEngine |
createScript(String nameOrExtOrMime)
创建
ScriptEngine 实例 |
static Object |
eval(String script)
执行有返回值的Javascript脚本
|
static Object |
eval(String script,
Bindings bindings)
执行有返回值的脚本
|
static Object |
eval(String script,
ScriptContext context)
执行有返回值的脚本
|
static Invocable |
evalInvocable(String script)
执行Javascript脚本,返回Invocable,此方法分为两种情况:
执行的脚本返回值是可执行的脚本方法
脚本为函数库,则ScriptEngine本身为可执行方法
|
static ScriptEngine |
getGroovyEngine()
获得单例的Groovy引擎
需要引入org.codehaus.groovy:groovy-all |
static JavaScriptEngine |
getJavaScriptEngine()
获得非单例的 Javascript引擎
JavaScriptEngine |
static ScriptEngine |
getJsEngine()
获得单例的JavaScript引擎
|
static ScriptEngine |
getLuaEngine()
获得单例的Lua引擎
需要引入org.luaj:luaj-jse |
static ScriptEngine |
getPythonEngine()
获得单例的Python引擎
需要引入org.python:jython |
static ScriptEngine |
getScript(String nameOrExtOrMime)
获得单例的
ScriptEngine 实例 |
static Object |
invoke(String script,
String func,
Object... args)
执行JS脚本中的指定方法
|
public static ScriptEngine getScript(String nameOrExtOrMime)
ScriptEngine
实例nameOrExtOrMime
- 脚本名称ScriptEngine
实例public static ScriptEngine createScript(String nameOrExtOrMime)
ScriptEngine
实例nameOrExtOrMime
- 脚本名称ScriptEngine
实例public static JavaScriptEngine getJavaScriptEngine()
JavaScriptEngine
JavaScriptEngine
public static ScriptEngine getJsEngine()
public static ScriptEngine createJsEngine()
public static ScriptEngine getPythonEngine()
public static ScriptEngine createPythonEngine()
public static ScriptEngine getLuaEngine()
public static ScriptEngine createLuaEngine()
public static ScriptEngine getGroovyEngine()
public static ScriptEngine createGroovyEngine()
public static Invocable evalInvocable(String script) throws ScriptRuntimeException
script
- 脚本内容ScriptRuntimeException
- 脚本异常public static Object eval(String script) throws ScriptRuntimeException
script
- 脚本内容ScriptRuntimeException
- 脚本异常public static Object eval(String script, ScriptContext context) throws ScriptRuntimeException
script
- 脚本内容context
- 脚本上下文ScriptRuntimeException
- 脚本异常public static Object eval(String script, Bindings bindings) throws ScriptRuntimeException
script
- 脚本内容bindings
- 绑定的参数ScriptRuntimeException
- 脚本异常public static Object invoke(String script, String func, Object... args)
script
- js脚本func
- 方法名args
- 方法参数public static CompiledScript compile(String script) throws ScriptRuntimeException
script
- 脚本内容CompiledScript
ScriptRuntimeException
- 脚本异常public static CompiledScript compile(ScriptEngine engine, String script) throws ScriptException
engine
- 引擎script
- 脚本内容CompiledScript
ScriptException
- 脚本异常Copyright © 2024. All rights reserved.