Java:ScriptEngine执行js代码
程序员文章站
2022-06-07 13:22:53
...
JDK >= 6
package com.demo.desktop;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class JavaScriptDemo {
public static void main(String[] args) throws ScriptException {
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("javascript");
String script = "print('Hello')";
// 执行脚本
engine.eval(script);
}
}
上一篇: 通过线程八锁问题融会贯通sychronized关键字的使用
下一篇: JS代码运行延迟