it's a simple example to print hello message using "nashorn" ScriptEngine.
package javatestnashornjavascript; import java.util.logging.Level; import java.util.logging.Logger; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; /** * @web http://java-buddy.blogspot.com/ */ public class JavaTestNashornJavascript { public static void main(String[] args) { ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine nashorn = scriptEngineManager.getEngineByName("nashorn"); try { nashorn.eval( "print('Hello from java-buddy, with nashorn JavaScript Engine.');"); } catch (ScriptException ex) { Logger.getLogger(JavaTestNashornJavascript.class .getName()).log(Level.SEVERE, null, ex); } } }
more nashorn JavaScript exercise:
No comments:
Post a Comment