getEngineByName(“nashorn”) returns null

蓝咒 提交于 2019-12-05 02:10:18

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.

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

ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine();

Nashorn is Oracle library, so if you have not Oracle Java then you should import it manually.

How to make use of Nashorn

This code is correct and work both on Oracle JDK and OpenJDK.

ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");

You should use the last version of the JDK 8 (the "ea" version you used is outdated now and probably buggy).

The official documentation of Nashorn is here: http://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/intro.html#sthref14

Nashorn is an OpenJDK project hosted here: http://openjdk.java.net/projects/nashorn/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!