1

My java application which is packaged with java 7 gave the following stack trace on a customers computer. It seems to be trying to use a Java 8 new Javascript engine even though it is definently running Java 7, any ideas ?

java.lang.NoClassDefFoundError: Could not initialize class jdk.nashorn.internal.objects.Global
at jdk.nashorn.internal.runtime.Context.newGlobal(Context.java:778)
at jdk.nashorn.api.scripting.NashornScriptEngine$3.run(NashornScriptEngine.java:425)
at jdk.nashorn.api.scripting.NashornScriptEngine$3.run(NashornScriptEngine.java:421)
at java.security.AccessController.doPrivileged(Native Method)
at jdk.nashorn.api.scripting.NashornScriptEngine.createNashornGlobal(NashornScriptEngine.java:421)
at jdk.nashorn.api.scripting.NashornScriptEngine.<init>(NashornScriptEngine.java:181)
at jdk.nashorn.api.scripting.NashornScriptEngine.<init>(NashornScriptEngine.java:152)
at jdk.nashorn.api.scripting.NashornScriptEngineFactory.getScriptEngine(NashornScriptEngineFactory.java:141)
at javax.script.ScriptEngineManager.getEngineByName(Unknown Source)

I dont know if he has Java 8 installed (butIve asked) but I do know he is actually using Java 7 to run the application because an automatic check and log I do at startup. which gives

18/02/2014 21.47.09:com.jthink.songkong.cmdline.SongKong:writeSystemInfo:INFO: SongKong 1.17.0 using Java 1.7.0_45 24.45-b08 32bit on Windows 7 6.1 x86 initialized successfully

The failing code is simply:

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
3
  • Can you post the code that leads to this? Commented Feb 22, 2014 at 14:52
  • Code looks fine. Did you compile your code using Java8? That can be the problem - not sure though! Commented Feb 22, 2014 at 17:43
  • Yes, I may have done because I do have java 8 installed, but why would a> that be a problem. b> only seem to be a problem for this customer ? Commented Feb 22, 2014 at 18:06

1 Answer 1

2

I had a bit of a dig around ...

The javax.script.ScriptEngineManager relies on a SPI mechanism to find and register ScriptEngineFactory classes. Essentially, it trawls the classpath, looking for these classes. Apparently, in in your case, this has resulted in it finding NashornScriptEngineFactory.

But why?

Well there are only really 3 possibilities:

  • You have a JAR file that includes Nashorn on your application's classpath.

  • You are using a JVM that includes Nashorn in one of its JAR files.

  • Someone has added the Nashorn in the Java installation's extensions directory.

To find out which, I suggest that you use find to find all of the JAR files on the client system, then use jar tvf some.jar | grep Nashorn to try to find which JAR is providing the Nashorn classes.

Sign up to request clarification or add additional context in comments.

7 Comments

Sorry Ive now clarified that the application is being run using Java 7, Ive added log excerpt to confirm this. I'm not using java 8 simply because the prereleases have all done a funny things with installers not rendering gui button correctly, if this is fixed I would be happy to move to Java 8 but I don't understand why a Java 7 install is looking for Java 8 code.
They haven't come back to me (its a Windows 7 system actually). But I have tried out latest Java 8 and looks fine so will bundle Java 8 JRE and build with Java 8 JDK for next version hopefully that will solve his issue, thanks.
Answer is sitting next to this post on right hand side "Nashorn under Java 7" : stackoverflow.com/questions/16929981/nashorn-under-java-7?rq=1.
@RaviH - No it isn't. >>This<< question is about why Nashorn is being used on Java 7 at all. The OP doesn't want it. Or at least, that is my interpretation. He just wants a working Javascript engine ...
@StephenC In one plane that question itself answers - naive attempt to run Nashorn engine in Java 7 fails with the same error. Apparently Paul Taylor's customer getting this error has done that kind of naive attempt to run Nashorn under Java 7 by just including nashorn jar in classpath. If at all that person really needs to run nashorn under java 7, that person has to try the Java 7 backport as suggested in the answer to that post.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.