Java examples for Scripting:Run Script
Printing a Message on the Standard Output Using Nashorn
import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class Main { public static void main(String[] args) { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); String script = "print('Hello Scripting!')"; try {//from w w w.j ava 2 s .co m engine.eval(script); } catch (ScriptException e) { e.printStackTrace(); } } }