Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getEngineByName("nashorn") returns null

Cant get Nashorn engine

ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
engine.eval("print('Hello World!');");

engine returns null

I am using eclipse, jdk1.8.0_11

java -version

java version "1.8.0_20-ea"

Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b23)

like image 374
Artur Avatar asked Aug 15 '14 19:08

Artur


2 Answers

Its working when I pass null param into ScriptEngineManager constructor:

ScriptEngine engine = new ScriptEngineManager(null).getEngineByName("nashorn");
engine.eval("print('Hello World!');");

from java docs

ScriptEngineManager(ClassLoader loader)

If loader is null, the script engine factories that are bundled with the platform and that are in the usual extension directories (installed extensions) are loaded.

like image 72
Artur Avatar answered Sep 23 '22 23:09

Artur


Old question but in case you didn't have any joy... you might try this instead...

ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine();
like image 25
Marrow父 Avatar answered Sep 25 '22 23:09

Marrow父