Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top