public static void main(String[] args) { ScriptEngineManager engineManager = new ScriptEngineManager(); ScriptEngine engine = engineManager.getEngineByName("JavaScript"); // 得到脚本引擎 try { engine.eval(new FileReader("src/main/webapp/test.js")); Invocable inv = (Invocable) engine; Object a = inv.invokeFunction("test"); System.out.println(a); } catch (FileNotFoundException | ScriptException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } }