Question

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");
Was it helpful?

Solution

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.

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