Java NoClassDefFoundError-RunListener:Maven surefire/JUnit

Java NoClassDefFoundError-RunListener:Maven surefire/JUnit,java,eclipse,maven,junit,Java,Eclipse,Maven,Junit,我一直在使用eclipse和maven学习关于JavaEE的PluralSight课程。我目前正在尝试编写一些测试,但在从cmd行运行mvn package时,我遇到了以下错误: 目标org.apache.maven.plugins的执行默认测试:maven surefire plugin:2.19.1:测试失败:分叉过程中出现错误 有时它指: java.lang.NoClassDefFoundError:org/junit/runner/notification/RunListener 有时:

我一直在使用eclipse和maven学习关于JavaEE的PluralSight课程。我目前正在尝试编写一些测试,但在从cmd行运行
mvn package
时,我遇到了以下错误:

目标org.apache.maven.plugins的执行默认测试:maven surefire plugin:2.19.1:测试失败:分叉过程中出现错误

有时它指:

java.lang.NoClassDefFoundError:org/junit/runner/notification/RunListener

有时:

java.lang.NoClassDefFoundError:org/junit/runner/Description

我已经做了一些阅读,RunListener似乎已经在JUnit4.0中引入。但据我所知,我有正确的依赖关系——JUnit4.12在我的依赖关系层次结构中。为了解决这个问题,我把所有的文件都改成了练习文件

我猜可能我根本上误解了maven和依赖项是如何工作的,重新jar和类路径,我仍然需要将eclipse或cmd行指向JUnit jar?(我在这两方面都有相同的错误)。我只是觉得奇怪,因为在我的java对象中可以识别出其他JUnit类。 这是我(pluralsight)的pom:

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

        <modelVersion>4.0.0</modelVersion>
        <groupId>com.pluralsight.javaee-getting-started.javaee-getting-started-m6</groupId>
        <artifactId>bookstore-back</artifactId>
        <version>1.0</version>
        <packaging>war</packaging>
        <name>Getting Started :: javaee-getting-started-m6 :: Testing the Repository :: Back</name>

        <properties>
            <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <!-- Test -->
            <version.junit>4.12</version.junit>
            <version.arquillian>1.1.13.5</version.arquillian>
            <version.arquillian.wildfly>2.0.2.Final</version.arquillian.wildfly>
            <version.shrinkwrap>1.2.6</version.shrinkwrap>
            <!-- Plugins -->
            <version.surefire.plugin>2.19.1</version.surefire.plugin>
        </properties>

        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.arquillian</groupId>
                    <artifactId>arquillian-universe</artifactId>
                    <version>${version.arquillian}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>

        <dependencies>
            <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-web-api</artifactId>
                <version>7.0</version>
                <scope>provided</scope>
            </dependency>

            <!-- TEST -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${version.junit}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.arquillian.universe</groupId>
                <artifactId>arquillian-junit</artifactId>
                <scope>test</scope>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>org.jboss.shrinkwrap</groupId>
                <artifactId>shrinkwrap-api</artifactId>
                <version>${version.shrinkwrap}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.wildfly.arquillian</groupId>
                <artifactId>wildfly-arquillian-container-remote</artifactId>
                <version>${version.arquillian.wildfly}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>

        <build>
            <finalName>bookstore-back</finalName>

            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${version.surefire.plugin}</version>
                    <configuration>
                        <systemPropertyVariables>
                            <arquillian.launch>arquillian-wildfly-remote</arquillian.launch>
                        </systemPropertyVariables>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <compilerArguments>
                            <endorseddirs>${endorsed.dir}</endorseddirs>
                        </compilerArguments>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.3</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.6</version>
                    <executions>
                        <execution>
                            <phase>validate</phase>
                            <goals>
                                <goal>copy</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${endorsed.dir}</outputDirectory>
                                <silent>true</silent>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>javax</groupId>
                                        <artifactId>javaee-endorsed-api</artifactId>
                                        <version>7.0</version>
                                        <type>jar</type>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.0.0</version>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>src</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                </plugin>
            </plugins>
        </build>

    </project>

4.0.0
com.pluralsight.javaee-getting-started.javaee-getting-started-m6
回书店
1
战争
Getting Started::javaee-Getting-Started-m6::测试存储库::返回
${project.build.directory}/project
UTF-8
4.12
1.1.13.5
2.0.2.2最终版本
1.2.6
2.19.1
org.arquillian
阿奎利安宇宙
${version.arquillian}
聚甲醛
进口
爪哇
javaeewebapi
7
假如
朱尼特
朱尼特
${version.junit}
测试
org.arquillian.universe
阿奎利安朱松
测试
聚甲醛
org.jboss.shrinkwrap
收缩包装api
${version.shrinkwrap}
测试
org.wildfly.arquillian
wildfly arquillian集装箱遥控器
${version.arquillian.wildfly}
测试
回书店
maven surefire插件
${version.surefire.plugin}
阿奎利安野蝇遥控器
org.apache.maven.plugins
maven编译器插件
3.1
1.8
1.8
${annowed.dir}
org.apache.maven.plugins
maven战争插件
2.3
假的
org.apache.maven.plugins
maven依赖插件
2.6
验证
复制
${annowed.dir}
真的
爪哇
javaee认可的api
7
罐子
maven汇编插件
3.0.0
src

我的类路径思想正确吗

删除Maven存储其依赖项的.m2文件夹,然后进行另一次构建。有时jar文件会损坏(例如Junit jar文件可能会损坏,这可以解释为什么它找不到类)。

删除Maven存储其依赖项的.m2文件夹,然后进行另一次构建。有时jar文件会损坏(例如Junit jar文件可能已损坏,这可以解释它找不到类的原因)。

首先尝试删除Maven存储其依赖项的
.m2
文件夹,然后进行另一次构建。有时jar文件会损坏(例如Junit jar文件可能损坏,这可以解释为什么它找不到类)。同时运行
mvn依赖关系树
,检查您是否确实拥有正确的版本(尽管根据您的pom应该可以)。另外,您所有的测试都在
src/test/java
下,对吗?删除了我的.m2文件并重新打包-我想您解决了这个问题-这已经标记了一个旧的问题。不过谢谢你!我现在发现运行时异常
无法连接到http-remoting://127.0.0.1:9990
。这虽然令人恼火,但至少是我在尝试运行jboss-cli.bat--connect--controller=localhost:9990时遇到的错误。我哈