karatelabs / karate

Test Automation Made Simple
https://karatelabs.github.io/karate
MIT License
8.34k stars 1.95k forks source link

Getting java.lang.NoClassDefFoundError: jdk/nashorn/api/scripting/ScriptObjectMirror while running on Linux box #200

Closed cnrani closed 7 years ago

cnrani commented 7 years ago

Hi Peter,

We have written webservice tests in karate and able to run the tests on local mac machine but currently getting the error java.lang.NoClassDefFoundError: jdk/nashorn/api/scripting/ScriptObjectMirror while running on Linux box. Initially we were getting nullpointer exception and sent a PR and after the merge, we started getting another issue "java.lang.NoClassDefFoundError: jdk/nashorn/api/scripting/NashornScriptEngineFactory". We sent the PR for to fix this and now we are getting another issue "java.lang.NoClassDefFoundError: jdk/nashorn/api/scripting/ScriptObjectMirror". The Java version on my mac and TEP(linux) is same and the only difference is operating system. Do you have any fix for this.

Thanks, Rani

ptrthomas commented 7 years ago

Rani - I have a feeling TEP may be relying on OpenJDK, I am not 100% sure, but maybe Karate needs the Oracle JDK to work properly. Can you confirm the exact JDK version, but I will also investigate.

ptrthomas commented 7 years ago

adding some context. Karate's CI has been running regularly on Ubuntu / Linux with this Travis setup: https://github.com/intuit/karate/blob/master/.travis.yml

ptrthomas commented 7 years ago

closing as duplicate of #196

amitnagesh commented 7 years ago

@ptrthomas I got same error on TEP job.

Java version: /usr/java/default/bin/java java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

Stacktrace:

Caused by: java.lang.ClassNotFoundException: jdk.nashorn.api.scripting.ScriptObjectMirror at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.apache.maven.surefire.booter.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:97) at com.intuit.karate.ScriptValue.(ScriptValue.java:330) at com.intuit.karate.ScriptValue.(ScriptValue.java:315) at com.intuit.karate.Script.evalInNashorn(Script.java:420) at com.intuit.karate.Script.evalInNashorn(Script.java:394) at com.intuit.karate.Script.eval(Script.java:316) at com.intuit.karate.Script.eval(Script.java:194) at com.intuit.karate.ScriptContext.(ScriptContext.java:114) at com.intuit.karate.StepDefs.(StepDefs.java:81) at com.intuit.karate.cucumber.KarateObjectFactory.getInstance(KarateObjectFactory.java:80) at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38) at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37) at com.intuit.karate.cucumber.CucumberUtils.runStep(CucumberUtils.java:136) at com.intuit.karate.cucumber.KarateRuntime.runStep(KarateRuntime.java:78)

ptrthomas commented 7 years ago

@amitnagesh refer #196 this is because only the JRE is installed. please work with the folks who own the build node and fix, this is not an issue with karate, thanks.

vnayar commented 6 years ago

This problem can be resolved by updating Maven to 3.6.0 as well if you can. However, if using openjdk, another problem will arise with an error stating "cannot load FreeBooter" or something like that. Fixing this by adding the maven-surefire-plugin configuration <useSystemClassLoader>false</useSystemClassLoader> fixes the above problem, but creates the problem reported in this issue.

To fix both problems, update Maven to 3.6.0 and also update Maven Surefire Plugin to 3.0.0-M1. Updating Maven will fix the problem alone if you are using Oracle JDK, but not for OpenSDK.

To fix the problem while using openjdk, change your Maven Surefire Plugin to the following:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M1</version>
                ...
            </plugin>
ptrthomas commented 6 years ago

thanks @vnayar !

rrowlands commented 4 years ago

I encountered this as a result of having the following surefire plugin configuration:

    <configuration>
      <forkCount>0</forkCount>
    </configuration>

My guess as to whats happening: The software you're running requires a jdk, however maven runs with the jre. If you don't fork then you'll be using maven's JRE, instead of forking into a new JDK.

ptrthomas commented 4 years ago

@rrowlands thanks ! that makes sense and explains some of the observations. I'll point others to this when needed. also provides some ideas on better detection of this case in the future, at least for more helpful logs