首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Spring Boot无法运行maven-surefire-plugin ClassNotFoundException org.apache.maven.surefire.booter.ForkedBooter

Spring Boot无法运行maven-surefire-plugin ClassNotFoundException org.apache.maven.surefire.booter.ForkedBooter
EN

Stack Overflow用户
提问于 2018-06-03 06:21:14
回答 5查看 31.6K关注 0票数 63

运行maven (3.5.2)构建的Spring Boot 2.0.2 generated应用程序(由具有web依赖关系的web初始化程序生成)无法执行maven-surefire-plugin,原因如下:

错误:无法找到或加载主类org.apache.maven.surefire.booter.ForkedBooter

原因: java.lang.ClassNotFoundException:org.apache.maven.surefire.booter.ForkedBooter

为什么会发生这种情况?是不是boot + surefire集成的问题= bug?

作为参考,看起来相关的依赖项是:

代码语言:javascript
复制
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.2.RELEASE</version>
    <relativePath/>
</parent>
...
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
</dependency>
...
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
</dependency>
...
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2018-06-03 06:21:14

该问题的解决方法是覆盖Spring Boot的maven-surefire-plugin定义,并将useSystemClassLoader设置为false。请阅读Surefire docs了解更多详细信息

代码语言:javascript
复制
<build>
    <plugins>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <useSystemClassLoader>false</useSystemClassLoader>
            </configuration>
        </plugin>
    </plugins>
</build>
票数 131
EN

Stack Overflow用户

发布于 2018-10-31 20:52:16

jediz提供的<useSystemClassLoader>false</useSystemClassLoader>解决方案确实允许我的surefire测试运行,但在我的一些Spring Boot集成测试中破坏了类加载。

下面的maven-surefire-plugin配置对我有效:

代码语言:javascript
复制
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
    </configuration>
</plugin>
票数 21
EN

Stack Overflow用户

发布于 2018-11-12 19:42:43

这是由于known bug in the Maven Surefire plugin造成的。在3.0.0-M1版本中已修复,该版本为released in November 2018。因此,最简单、最可靠的修复方法是升级您使用的插件的版本。

将maven-surefire-plugin从2.12.4更新到3.0.0-M1对我有效。该项目没有显式地使用插件,所以我必须添加一个新的插件依赖项。

代码语言:javascript
复制
<plugins>
   ...
   <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>3.0.0-M1</version>
   </plugin>
   ...
</plugins>
票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50661648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档