gpt4 book ai didi

java - NoClassDefFoundError - RunListener : Maven-surefire/JUnit

转载 作者:行者123 更新时间:2023-12-02 02:26:42 25 4
gpt4 key购买 nike

我一直在使用 eclipse 和 maven 学习关于 JavaEE 的 PluralSight 类(class)。我目前正在尝试编写一些测试,但是在运行 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

我已经阅读了一些内容,并且 RunListener 似乎已在 JUnit 4.0 中引入。但据我所知,我有正确的依赖关系 - JUnit 4.12 在我的依赖关系层次结构中。现在,我已将所有文件更改为练习文件,以便解决此问题。

我猜测也许我从根本上误解了 Maven 和依赖项的工作方式、RE 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>

我的类路径想法是否走在正确的轨道上?

最佳答案

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

关于java - NoClassDefFoundError - RunListener : Maven-surefire/JUnit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47679324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com