草庐IT

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

coder 2023-05-10 原文

运行 Spring Boot 2.0.2.RELEASE 应用程序的 maven (3.5.2) 构建(由具有 Web 依赖项的 Web 初始化程序生成)无法执行 ma​​ven-surefire-plugin 只是说:

Error: Could not find or load main class org.apache.maven.surefire.booter.ForkedBooter

Caused by: java.lang.ClassNotFoundException: org.apache.maven.surefire.booter.ForkedBooter

为什么会这样?它是引导中的问题+肯定集成=错误吗?

作为引用,看起来相关的依赖项是:

<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>

最佳答案

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

<build>
    <plugins>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <useSystemClassLoader>false</useSystemClassLoader>
            </configuration>
        </plugin>
    </plugins>
</build>

关于Spring Boot 无法运行 maven-surefire-plugin ClassNotFoundException org.apache.maven.surefire.booter.ForkedBooter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50661648/

有关Spring Boot 无法运行 maven-surefire-plugin ClassNotFoundException org.apache.maven.surefire.booter.ForkedBooter的更多相关文章

随机推荐