Nashorn under Java 7

你。 提交于 2020-01-28 10:44:17

问题


I'm trying to get Oracle's Nashorn running under Java 7.

I've cloned the repo and compiled the source. All I had to do to get it to compile was:

  • Change jdk.internal.org.objectweb.asm.* to org.objectweb.asm.*
  • Change one line that had Long.hashCode() static.

Everything seems happy, and Java 7 sees Nashorn as a scripting engine; but when I try and get an instance:

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

I get the exception:

java.lang.RuntimeException: java.lang.ClassNotFoundException: jdk.nashorn.internal.objects.Global at jdk.nashorn.internal.runtime.Context.newGlobalTrusted(Context.java:831) at jdk.nashorn.internal.runtime.Context.newGlobal(Context.java:636) at jdk.nashorn.api.scripting.NashornScriptEngine$2.run(NashornScriptEngine.java:270) at jdk.nashorn.api.scripting.NashornScriptEngine$2.run(NashornScriptEngine.java:266) at java.security.AccessController.doPrivileged(Native Method) at jdk.nashorn.api.scripting.NashornScriptEngine.createNashornGlobal(NashornScriptEngine.java:266) at jdk.nashorn.api.scripting.NashornScriptEngine.(NashornScriptEngine.java:104) at jdk.nashorn.api.scripting.NashornScriptEngine.(NashornScriptEngine.java:78) at jdk.nashorn.api.scripting.NashornScriptEngineFactory.getScriptEngine(NashornScriptEngineFactory.java:139)

jdk.nashorn.internal.objects.Global is in my class path. Does Nashorn use a different class loader maybe?


回答1:


I tried getting it to work under 7 previously and was met by the same error as you have. I think it has to do with the fact that Nashorn makes use of some new features in Java 8.

There is a backport of Nashorn for JDK 7 on bitbucket; I wrote a blog post detailing how to use it on my works blog here. You can also look at this stack overflow question for more information.

That bitbucket project hasn't been updated in some time, I'd recommend that you use the preview of Java 8 if you want to play with Nashorn.



来源:https://stackoverflow.com/questions/16929981/nashorn-under-java-7

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