cumber抛出java.lang.noclassdeffounderror:io/cumber/core/gherkin/featureparser

oogrdqng  于 2021-06-29  发布在  Java
关注(0)|答案(2)|浏览(338)

我在学习cucumber,我得到了featureparser错误

java.lang.NoClassDefFoundError: io/cucumber/core/gherkin/FeatureParser

我已经导入了以下jar文件
小 cucumber -9.2.0.jar
cucumber 芯-5.2.0.jar
cucumber-java-5.2.0.jar文件
cucumber -junit-5.2.0.jar
cucumber-jvm-deps-1.0.6.jar文件
cucumber-plugin-5.2.0.jar文件
我写了如下代码
logintestrunner.java文件

package cucumberTests;

import org.junit.runner.RunWith;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(features="features", glue="stepImplementations")
public class LoginTestRunner {

}

我也写了功能文件。
获取以下错误:

java.lang.NoClassDefFoundError: io/cucumber/core/gherkin/FeatureParser
    at io.cucumber.core.feature.FeatureParser.parseResource(FeatureParser.java:35)
    at io.cucumber.core.runtime.FeaturePathFeatureSupplier.lambda$new$0(FeaturePathFeatureSupplier.java:39)
    at java.base/java.util.function.BiFunction.lambda$andThen$0(BiFunction.java:70)
    at io.cucumber.core.resource.ResourceScanner.lambda$processResource$2(ResourceScanner.java:126)
    at io.cucumber.core.resource.PathScanner$ResourceFileVisitor.visitFile(PathScanner.java:67)
    at io.cucumber.core.resource.PathScanner$ResourceFileVisitor.visitFile(PathScanner.java:52)
    at java.base/java.nio.file.Files.walkFileTree(Files.java:2724)
    at java.base/java.nio.file.Files.walkFileTree(Files.java:2796)
    at io.cucumber.core.resource.PathScanner.findResourcesForPath(PathScanner.java:46)
    at io.cucumber.core.resource.PathScanner.findResourcesForUri(PathScanner.java:26)
    at io.cucumber.core.resource.ResourceScanner.findResourcesForUri(ResourceScanner.java:109)
    at io.cucumber.core.resource.ResourceScanner.scanForResourcesUri(ResourceScanner.java:86)
    at io.cucumber.core.runtime.FeaturePathFeatureSupplier.loadFeatures(FeaturePathFeatureSupplier.java:62)
    at io.cucumber.core.runtime.FeaturePathFeatureSupplier.get(FeaturePathFeatureSupplier.java:46)
    at io.cucumber.junit.Cucumber.<init>(Cucumber.java:156)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.vintage.engine.discovery.DefensiveAllDefaultPossibilitiesBuilder$DefensiveAnnotatedBuilder.buildRunner(DefensiveAllDefaultPossibilitiesBuilder.java:113)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.vintage.engine.discovery.DefensiveAllDefaultPossibilitiesBuilder.runnerForClass(DefensiveAllDefaultPossibilitiesBuilder.java:56)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.vintage.engine.discovery.ClassSelectorResolver.resolveTestClass(ClassSelectorResolver.java:66)
    at org.junit.vintage.engine.discovery.ClassSelectorResolver.resolve(ClassSelectorResolver.java:47)
    at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.lambda$resolve$2(EngineDiscoveryRequestResolution.java:129)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1631)
    at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
    at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
    at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:174)
    at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:120)
    at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:87)
    at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.run(EngineDiscoveryRequestResolution.java:80)
    at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver.resolve(EngineDiscoveryRequestResolver.java:112)
    at org.junit.vintage.engine.discovery.VintageDiscoverer.discover(VintageDiscoverer.java:42)
    at org.junit.vintage.engine.VintageTestEngine.discover(VintageTestEngine.java:62)
    at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:177)
    at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:164)
    at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:120)
    at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.<init>(JUnit5TestReference.java:45)
    at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createUnfilteredTest(JUnit5TestLoader.java:76)
    at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.createTest(JUnit5TestLoader.java:66)
    at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.loadTests(JUnit5TestLoader.java:53)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:526)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: java.lang.ClassNotFoundException: io.cucumber.core.gherkin.FeatureParser
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 56 more
vddsk6oq

vddsk6oq1#

我在学习cucumber,我得到了featureparser错误
如果您遵循10分钟的教程,您将得到一个使用maven依赖关系管理的介绍。
除了本教程之外,我强烈建议您花时间学习maven或gradle以及cucumber。除此之外,这些工具将自动化您的依赖关系管理,这可以使您的生活更加轻松。
例如:
如果您想将cucumber与junit4和基于注解的步骤定义一起使用,您可以在maven中声明这个最小的依赖集 pom.xml 文件。

<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>

通过告诉maven您的依赖关系是什么,maven可以计算您的可传递依赖关系,即:依赖关系的依赖关系。
这有很多优点。一个例子是使用 mvn dependency:tree 命令将列出所有依赖项。这比手工下载jar文件并希望得到正确的jar文件要快得多,也不容易出错。

$ 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] ------------------------------------------------------------------------
92vpleto

92vpleto2#

添加以下依赖项并重新生成项目:
注意,范围设置为test-- java.lang.NoClassDefFoundError 在编译时找到类时抛出,但在运行时没有。所以您需要确保这个.jar在运行时可用

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>5.1.3</version>
    <scope>test</scope>
</dependency>

如果您使用的是eclipse,请确保已将项目类路径设置为包含依赖项,并且已将其构建并嵌入到项目中

相关问题