首页 > 解决方案 > 添加测试依赖项后的 NoClassDefFoundError

问题描述

我在有线测试中添加了 hamcrest 方法,在构建过程中,它成功了。

但是当我尝试执行测试时,它抛出了java.lang.NoClassDefFoundError: org/hamcrest/Matchers错误。

我尝试将 hamcerst 依赖项添加到包 pom 中,如下所示(即使依赖项已经存在于父 pom 中):

        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <scope>test</scope>
        </dependency>

但是我NoClassDefFoundError在运行时仍然遇到同样的错误。为什么?

标签: javadependenciesnoclassdeffounderrorhamcrest

解决方案


推荐阅读