0

I am facing an error whenever I run the cucumber program by Junit. Here the errors. Any help will be awesome

But in a program, there is no error.

java.lang.NoClassDefFoundError: cucumber/io/ResourceLoader
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at cucumber.runtime.Reflections.hasConstructor(Reflections.java:53)
at cucumber.runtime.Reflections.instantiateSubclasses(Reflections.java:)
at cucumber.runtime.Runtime.loadBackends(Runtime.java:87)
at cucumber.runtime.Runtime.<init>(Runtime.java:41)
at cucumber.api.junit.Cucumber.createRuntime(Cucumber.java:84)
at cucumber.api.junit.Cucumber.<init>(Cucumber.java:63)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(UnknownSource)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.junit.internal.requests.ClassRequest.buildRunner(ClassRequest.java:33)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:90)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:76)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:49)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:525)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)

Caused by: java.lang.ClassNotFoundException: cucumber.io.ResourceLoader
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 23 more

I want to run my program but the system gives an error.

  • 1
    Possible duplicate of [Cucumber Exception: java.lang.ClassNotFoundException: cucumber.io.ResourceLoader](https://stackoverflow.com/questions/25291480/cucumber-exception-java-lang-classnotfoundexception-cucumber-io-resourceloader) – nullPointer Jan 23 '19 at 12:45

4 Answers4

1

Please make sure you have the correct Cucumber dependency / dependencies. You can find which ones you need and their latest version in the docs

If you are using multiple Cucumber dependencies, please make sure to use the same version for all, to avoid conflicts.

Marit
  • 2,399
  • 18
  • 27
1

Here are the minimum dependencies needed to get your Cucumber running:

Cucumber-java (1.2.2) | Cucumber-junit (1.2.2) | Cucumber-picocontainer (1.2.2) |junit (4.12)

Maven manages the rest of the dependencies. Make sure you have the latest dependencies, and that you are not mixing and matching versions (all shall follow 1.2.2/4.0.0 version)

Please share your POM.XML dependencies.

TheSociety
  • 1,936
  • 2
  • 8
  • 20
0

You're probably missing the cucumber-core.jar from your classpath

nullPointer
  • 4,419
  • 1
  • 15
  • 27
0

Hope yours is NOT a maven project or you didnt add cucumber-core dependency in your pom.xml. I can see the solution already provided by @funkyjelly, please go through that.

Bhuvanesh Mani
  • 1,394
  • 14
  • 23
  • I have already added cucumber-core dependency but it doesn't run – AJay Shehrawat Jan 24 '19 at 10:03
  • Can you please check in your .m2 repository if cucumber-core jar has been downloaded? if you're under corporate firewall, they don't allow downloading dependencies from maven repo instead you should use their own corporate repo to get this jar file. Most likely, i think this jar never got downloaded into your repo. – Bhuvanesh Mani Feb 13 '19 at 10:05