代码之家  ›  专栏  ›  技术社区  ›  jediz 114326671

spring boot无法运行maven surefire plugin classnotfoundexception org.apache.maven.surefire.booter.forkedbooter

  •  54
  • jediz 114326671  · 技术社区  · 7 年前

    运行maven(3.5.2)构建 弹簧靴 2.0.2.Release应用程序(由具有Web依赖项的Web初始化程序生成)无法执行 Maven Surefire插件 只是说:

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

    原因:java.lang。 类NotFoundException :org.apache.maven.surefire.booter。 叉靴

    为什么会这样?在boot+surefire集成中有问题吗=一个bug?

    作为参考,似乎相关的依赖项包括:

    <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>
    
    5 回复  |  直到 6 年前
        1
  •  119
  •   jediz 114326671    7 年前

    解决这个问题的方法是覆盖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>
    
        2
  •  17
  •   Andreas Presthammer    6 年前

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

    以下Maven Surefire插件配置对我有效:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
        </configuration>
    </plugin>
    
        3
  •  10
  •   peterh Eli    6 年前

    对我来说,解决方案是运行mvn

    _JAVA_OPTIONS=-Djdk.net.URLClassPath.disableClassPathURLCheck=true mvn clean compile package
    

    其他想法(将系统属性赋予maven参数列表,在 pom.xml , settings.xml )不起作用。

    尽管它没有包含精确的解,也 this answer 很有助于我澄清,这是ubuntu jdk和maven surefire插件中两个独立的、无害的bug的不幸合作。

    最近使用相同jdk和maven版本的debian(buster)似乎没有受到这个问题的影响,但是ubuntu(xenial)受到了影响。

    精确的解来自 this 回答。

        4
  •  9
  •   jediz 114326671    6 年前

    将maven surefire插件从2.12.4更新到3.0.0-m1对我很有用。这个项目没有显式地使用插件,所以我不得不添加一个新的插件依赖项。

    <plugins>
       ...
       <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>3.0.0-M1</version>
       </plugin>
       ...
    </plugins>
    
        5
  •  0
  •   GlenPeterson    6 年前

    在将这个添加到pom的顶部(在 <project> 节点)

    <prerequisites>
        <maven>3.6.1</maven>
    </prerequisites>
    

    为什么我认为这是正确的答案?

    • 它指定maven建议使用的maven版本: https://maven.apache.org/download.cgi
    • 当你跑的时候 mvn versions:display-plugin-updates 它显示它从super pom中获取了maven surefire插件3.0.0-m3,到目前为止似乎已经解决了这个问题。
    • 你不必单独管理插件版本。只是你的最小maven版本,控制超级pom版本。