Hello Nashorn
suggest changeNashorn was included in Java 8 through 14 and removed in Java 15. getEngineByName returns null when the engine is not installed, and calling eval on that null throws NullPointerException rather than ScriptException.
// Obtain an instance of the Nashorn JavaScript engine
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("nashorn");
// Execute a hardcoded script
try {
engine.eval("print('Hello Nashorn!');");
} catch (ScriptException ex) {
// Checked exception declared by ScriptEngine.eval
ex.printStackTrace();
}
// Outcome:
// 'Hello Nashorn!' printed on standard output
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents