Adrian Stewart Adrian Stewart - 16 days ago 5
Java Question

java.lang.NoClassDefFoundError in Cucumber test package

I am trying to set up a very simple Cucumber test environment using Eclipse. I am following a tutorial and created the project with required reference libraries:

Referenced Libraries

I have created the CucumberRunner.java file with the following content:

package cucumber;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)

@CucumberOptions(
plugin = { "pretty", "json:target/cucumber.json" },
features = "src/cucumber"
)

public class CucumberRunner {

}


and also create a feature file and step definitions. If I run the from, the feature files, the tests run correctly. But, if I run from the CucumberRunner.java, I get:

java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetPublicMethods(Class.java:2902)
at java.lang.Class.getMethods(Class.java:1615)
at cucumber.runtime.java.MethodScanner.scan(MethodScanner.java:40)
at cucumber.runtime.java.JavaBackend.loadGlue(JavaBackend.java:86)
at cucumber.runtime.Runtime.<init>(Runtime.java:92)
at cucumber.runtime.Runtime.<init>(Runtime.java:70)
at cucumber.runtime.Runtime.<init>(Runtime.java:66)
at cucumber.api.junit.Cucumber.createRuntime(Cucumber.java:80)
at cucumber.api.junit.Cucumber.<init>(Cucumber.java:59)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)


I have installed the Cucumber Eclipse Plugin as per another answered question so I am at a total loss as to why this is happening. If I try to add JARs to include the missing libraries, I just seem to move the problem to a difference missing library.

I think it must be to do with the versions of libraries I am using but I am a complete novice at this and have no experience of how to problem solve this.

Any help at all would be much appreciated.

Answer

As per Sid's comment above, renaming the cucumber class fixed this.

Comments