我一直在使用eclipse和maven关注JavaEE的PluralSight课程。我目前正在尝试编写一些测试,但是当从cmd行运行mvn package
时,我一直收到此错误:
Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed: There was an error in the forked process
有时它指的是:
java.lang.NoClassDefFoundError: org/junit/runner/notification/RunListener
有时候:
java.lang.NoClassDefFoundError: org/junit/runner/Description
我已经完成了一些阅读,并且似乎已经在JUnit 4.0中引入了RunListener。但据我所知,我有正确的依赖--JUnit 4.12在我的依赖层次结构中。我现在已将所有文件更改为练习文件,以便解决此问题。
我猜我可能从根本上误解了maven和依赖关系是如何工作的,RE jar和类路径,还是我还需要将eclipse或cmd行指向JUnit jar? (我在两者中都得到了相同的错误)。鉴于其他JUnit类在我的java对象中被识别,我发现这很奇怪。 无论如何,这是我的(复数的)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>
我是否正在使用classpath的想法?
答案 0 :(得分:0)
删除.m2文件夹,其中Maven存储它的依赖项并进行另一次构建。有时jar文件被破坏(例如,Junit jar文件可能已损坏,这可以解释为什么它找不到类)。