3

I am trying to setup my first Cucumber effort in Eclipse. I setup a basic feature file in the Features folder the way that the tutorial video suggested, but trying to execute as a cucumber feature, I get the following:

Exception in thread "main" java.lang.NoClassDefFoundError: gherkin/formatter/Formatter
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:821)
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:719)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:642)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:600)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    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:70)
    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.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 14 more

I have followed all the steps listed by the tutorial video I am watching, but no success. I have the following installed:

Eclipse 2019-12, Java SE 13

I downloaded and installed all the jar files locally. I have read that the potential for conflicts can arise with a large number of jar files that could interfere with one another so I updated all my jar files to the latest versions. Still no help. I then eliminated installed jars one at a time and attempted to run again until I got down to the bare necessities. The issue still persists.

Here is a snippet of my setup:

Snapshot of my project in Eclipse

I'm open to any help that others can provide

Community
  • 1
  • 1
mlrtyme
  • 41
  • 4

1 Answers1

1

I downloaded and installed all the jar files locally. I have read that the potential for conflicts can arise with a large number of jar files that could interfere with one another so I updated all my jar files to the latest versions. Still no help. I then eliminated installed jars one at a time and attempted to run again until I got down to the bare necessities. The issue still persists.

If you follow the 10 minute tutorial you'll get an introduction that uses Maven dependency management.

In addition to this tutorial I would strongly urge you to invest time in learning either Maven or Gradle along with Cucumber. Amongst other things these tools will automate your dependency management and this can make your life much easier.

For example:

If you want to use Cucumber with JUnit 4 and annotation based step definitions you would declare this minimal set of dependencies in a Maven pom.xml file.

    <properties>
        <cucumber.version>5.2.0</cucumber.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

By telling Maven what your dependencies are Maven can calculate your transitive dependencies i.e: the dependencies of your dependencies.

This has many advantages. One example would be using the mvn dependency:tree command to will list all dependencies. This is much faster and much less error prone then downloading jar files by hand and hoping that you have the right ones.

$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------< cucumber:cucumber-java-skeleton >-------------------
[INFO] Building Cucumber-Java Skeleton 0.0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ cucumber-java-skeleton ---
[INFO] cucumber:cucumber-java-skeleton:jar:0.0.1
[INFO] +- io.cucumber:cucumber-java:jar:5.2.0:test
[INFO] |  +- io.cucumber:cucumber-core:jar:5.2.0:test
[INFO] |  |  +- io.cucumber:cucumber-gherkin:jar:5.2.0:test
[INFO] |  |  +- io.cucumber:cucumber-gherkin-vintage:jar:5.2.0:test
[INFO] |  |  +- io.cucumber:tag-expressions:jar:2.0.4:test
[INFO] |  |  +- io.cucumber:cucumber-expressions:jar:8.3.1:test
[INFO] |  |  +- io.cucumber:datatable:jar:3.3.0:test
[INFO] |  |  +- io.cucumber:cucumber-plugin:jar:5.2.0:test
[INFO] |  |  \- io.cucumber:docstring:jar:5.2.0:test
[INFO] |  \- org.apiguardian:apiguardian-api:jar:1.1.0:test
[INFO] +- io.cucumber:cucumber-junit:jar:5.2.0:test
[INFO] \- junit:junit:jar:4.13:test
[INFO]    \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.781 s
[INFO] Finished at: 2020-02-10T23:00:14+01:00
[INFO] ------------------------------------------------------------------------
M.P. Korstanje
  • 10,426
  • 3
  • 36
  • 58