Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

javascript - Nashorn under Java 7

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...