问题
I am getting the following error with my cucumber setup. I was following a youtube video (https://www.youtube.com/watch?v=pD4B839qfos&list=PL_noPv5wmuO_t6yYbPfjwhJFOOcio89tI) for this setup but I downloaded all the latest jars. Not sure what went wrong but now I can't figure out what needs to be done. Can anyone help me, please?
Exception in thread "main" java.lang.NoClassDefFoundError: gherkin/formatter/Formatter
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at cucumber.runtime.formatter.PluginFactory$1.<init>(PluginFactory.java:53)
at cucumber.runtime.formatter.PluginFactory.<clinit>(PluginFactory.java:52)
at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:69)
at cucumber.api.cli.Main.run(Main.java:31)
at cucumber.api.cli.Main.main(Main.java:18)
Caused by: java.lang.ClassNotFoundException: gherkin.formatter.Formatter
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 17 more
回答1:
This means that Gherkin version you are using is not compatible with other Cucumber libraries. I tried using the latest gherkin3-3.0.0 but it did not work for me, so I degraded it to gherkin-2.12.2
I got below versions on Oct’17 for Cucumber
- cobertura-2.1.1
- cucumber-core-1.2.5
- cucumber-java-1.2.5
- cucumber-junit-1.2.5 cucumber-jvm-deps-1.0.5
- cucumber-reporting-3.10.0 gherkin-2.12.2 junit-4.12
- mockito-all-2.0.2-beta
The compatible version with your Cucumber-java can be found here under the Provided Dependencies section
If this does not resolve your issue make sure you remove jars from Project Build Path and add back again. Same if you are using maven then clearing local maven repository may also help.
You can also follow the steps mention in this tutorial
来源:https://stackoverflow.com/questions/32378974/noclassdeffounderror-while-setting-up-cucumber-tests