示例
public class Test {
public static void main(String[] args) throws ScriptException, NoSuchMethodException {
ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine se = sem.getEngineByName("javascript");
se.put("msg", "i love you");
String str = "var user= {name:'hu',age:16};";
str += "print(user.name)";
se.eval(str);
se.eval("function add(a,b){var sum = a+b;return sum}");
Invocable invoke = (Invocable) se;
Object result = invoke.invokeFunction("add", new Object[] {1,2});
System.out.println(result);
}
}