分叉的虚拟机终止而没有说再见。 VM崩溃或System.exit调用

时间:2014-04-24 04:47:31

标签: java maven-surefire-plugin opendaylight

请帮我解决这个问题。我不完全理解日志中的错误意味着什么。

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.749s
[INFO] Finished at: Thu Apr 24 10:10:20 IST 2014
[INFO] Final Memory: 15M/37M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.15:test (default-test) on project samples.simpleforwarding: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.15:test failed: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ?
[ERROR] Command wascmd.exe /X /C ""C:\Program Files\Java\jdk1.7.0_55\jre\bin\java" -Xmx1024m -XX:MaxPermSize=256m -jar E:\OpenDayLight\controller\opendaylight\samples\simpleforwarding\target\surefire\surefirebooter53410321571238933.jar E:\OpenDayLight\controller\opendaylight\samples\simpleforwarding\target\surefire\surefire86076271125218001tmp E:\OpenDayLight\controller\opendaylight\samples\simpleforwarding\target\surefire\surefire_01846991116135903536tmp"
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

56 个答案:

答案 0 :(得分:71)

我遇到了同样的问题并通过添加:

解决了
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>

整个插件元素是:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <forkCount>3</forkCount>
    <reuseForks>true</reuseForks>
    <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
  </configuration>
</plugin>

答案 1 :(得分:32)

截至今天(2018年10月30日),我们注意到Jenkins的构建因此错误而中断。

该错误有点令人误解,需要查看target/surefire-reports/中转储的输出以查看以下错误消息:

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

这使我进入以下SO帖子,其中提到了OpenJDK 181中的可能错误:Maven surefire could not find ForkedBooter class

该帖子中的任何修复均解决了我的问题。具体来说,我使用了其中一种:

  1. 从构建在Docker容器maven:3.5.4-jdk-8中切换到maven:3.5.4-jdk-8-alpine
  2. 覆盖Spring Boot的类加载器,在这里详细说明:https://stackoverflow.com/a/50661649/1228408

答案 2 :(得分:24)

我有一个非常相似的问题(Maven build and maven-failsafe-plugin - The forked VM terminated without properly saying goodbye),找到了三个对我有用的解决方案:

问题描述

问题仅在版本2.20.1和2.21.0中与maven插件 maven-surefire-plugin 有关。经过检查,您使用的是2.20.1版本。

解决方案1 ​​

将插件版本升级到 2.22.0 。添加 pom.xml

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.22.0</version>
</plugin>

解决方案2

将插件版本降级为 2.20 。添加 pom.xml

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.20</version>
</plugin>

解决方案3

使用插件配置 testFailureIgnore 。添加 pom.xml

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <testFailureIgnore>true</testFailureIgnore>
  </configuration>
</plugin>

答案 3 :(得分:19)

就我而言,此问题与将日志输出到IntelliJ IDEA控制台(OS Windows 10)中时间过长有关。

命令:

mvn clean install

此命令为我解决了这个问题:

mvn clean install > log-file.log

答案 4 :(得分:18)

这部分Surefire FAQ可以帮到你:

  

Surefire失败并显示消息“分叉的虚拟机未正常说再见”

     

Surefire不支持随时调用System.exit()的测试或任何引用库。如果他们这样做,他们与surefire不兼容,你可能应该向库/供应商提出问题。或者,分叉的VM也可能由于多种原因而崩溃,这也可能导致此问题发生。查找表示VM崩溃的经典“hs_err *”文件,或者在测试执行时检查运行maven的日志输出。崩溃进程的一些“非常”输出可能会被转储到控制台/日志中。如果这种情况发生在CI环境中并且仅在一段时间后运行,那么您的测试套件很可能会泄漏某种操作系统级别的资源,这会使每次运行都变得更糟。常规的os级监控工具可能会给你一些指示。

答案 5 :(得分:9)

面对同样的问题,ubuntu上的Java 8

然后遇到了https://stackoverflow.com/a/53016532/1676516

这似乎是使用Java 8 https://issues.apache.org/jira/browse/SUREFIRE-1588的surefire插件版本2.22.1中的最新错误

按照建议的解决方法通过本地mvn设置~/.m2/settings.xml

<profiles>
    <profile>
        <id>SUREFIRE-1588</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
        </properties>
    </profile>
</profiles>

答案 6 :(得分:6)

今天我遇到了同样的问题,对我来说,真正的问题是在日志中进一步报告,消息为Cannot use a threadCount parameter less than 1; 1 > 0。 在surefire-plugin配置中添加<threadCount>1</threadCount>时,其他错误消失了。

完整的插件配置:
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <dependencies>
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-junit47</artifactId>
                    <version>2.18.1</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-testng</artifactId>
                    <version>2.18.1</version>
                </dependency>
            </dependencies>
            <configuration>
                <threadCount>1</threadCount>
            </configuration>
        </plugin>

...是的,我在此测试框架中使用了junit和testng,以实现向后兼容性。

答案 7 :(得分:6)

在JDK 1.8.0_上运行带有Jacoco插件的mvn命令时出现类似问题 65

[INFO]
A fatal error has been detected by the Java Runtime Environment:

JRE version: Java(TM) SE Runtime Environment (8.0_65-b17) (build 1.8.0_65-b17).........
Problematic frame:
PhaseIdealLoop::build_loop_late_post(Node*)+0x144
............
............
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19:test (default-test) on project 

 The forked VM terminated without properly saying goodbye. VM crash or System.exit called?

JDK https://bugs.openjdk.java.net/browse/JDK-8081379

中存在错误

解决方案是使用param运行mvn clean install -XX:-UseLoopPredicate

或者只是对JDK进行更新(我认为较新的次要版本可以使用)

答案 8 :(得分:5)

我也在Jenkins Docker容器中遇到了这个问题(尝试了jenkins:lts,jenkins,jenkins:slim和jenkins:slim-lts。我不想遍历所有存储库并为每个项目更新pom ,所以我只是将disableClassPathURLCheck添加到了maven命令行调用中:

mvn test -DargLine="-Djdk.net.URLClassPath.disableClassPathURLCheck=true"

答案 9 :(得分:5)

关闭maven-surefile-plugin的useSystemClassLoader应该会帮助

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

答案 10 :(得分:4)

2.22.2版本对于分叉的JVM确实存在问题。 使用2.20版-就像魅力一样!


<groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>

答案 11 :(得分:3)

在某些Windows计算机上,这似乎是线程同步问题。如果您在Windows中遇到此问题,请尝试将输出重定向到文件:mvn clean install > output.txt

答案 12 :(得分:3)

我最近在 JHipster 6.10.5 使用 spring-boot 2.2.7.RELEASE 和 maven surefire 插件 3.0.0-M4 生成的应用程序中遇到了同样的问题。是由于测试日志超长导致超时。通过在 pom.xml 中的 maven-surefire-plugin(在 pluginManagement 下)添加以下配置参数来解决:

1200

https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#forkedProcessExitTimeoutInSeconds

答案 13 :(得分:3)

您需要检查您的机器是64位还是32位。如果您的机器是32位,那么您的内存参数不应超过4096,即使它应低于4 GB。 但如果你的机器是64位,那么安装Java 64位并在mvn.bat中提供JAVA_HOME,这指向java 64位安装。

答案 14 :(得分:2)

我遇到了一个案例,其中没有提供解决问题的方法。这是一个旧应用程序,恰好正在使用log4j和SLF4J / logback。

以前的情况:clean test构建在Eclipse中启动时运行良好,但是在命令行中启动时,发生了此错误。在CircleCI上构建CI也可以。

我所做的事情:纯粹出于猜测,是配置适当的logback-test.xml并降低日志记录的详细程度。瞧,我不再遇到此错误,现在可以从命令行构建项目(以及发生此错误的模块)。

我的观点是,使用或配置日志记录框架的方式可能是另一种解释

log4j和logback真的冲突吗?还是仅仅是测试产生的大量日志以某种方式使命令行缓冲区溢出?我不知道。对我来说仍然是个谜。

答案 15 :(得分:2)

我最近在用Bamboo构建我的容器化jar应用程序时遇到了这个错误:

  

org.apache.maven.surefire.booter.SurefireBooterForkException:分叉的VM终止,没有正确说再见

经过数小时的研究,我将其修复。而且我认为在这里分享我的解决方案会很有用。

因此,每次对docker容器中的Java应用程序执行Bamboo运行mvn clean package命令时,都会发生该错误。我不是Maven专家,但问题出在spring-boot中作为Maven依赖项包含的Surefire和Junit4插件。

要修复此问题,您需要将Junit4替换为Junit5,并在您的pom.xml中覆盖Surefire插件。

1。在内部spring boot依赖项插入排除项:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <!-- FIX BAMBOO DEPLOY>
    <exclusions>
        <exclusion>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </exclusion>
    </exclusions>
    <!---->
</dependency>

2。添加新的Junit5依赖项:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.1.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    <version>5.1.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>
    <version>1.1.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-runner</artifactId>
    <version>1.1.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-surefire-provider</artifactId>
    <version>1.1.0</version>
    <scope>test</scope>
</dependency>

3。在“插件”部分插入新插件

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <dependencies>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.1.0</version>
        </dependency>
    </dependencies>
</plugin>

这足以修复竹制品。别忘了还要转换所有Junit4测试以支持Junit5。

答案 16 :(得分:2)

在pom.xml中进行设置对我有用。 但是您应该查看文档以了解其他解决方法 https://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html

       <plugin>

            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <!--these strange settings fixes a chrash and dumpstream from surefire when run from command line
                    Caused by: java.lang.ClassNotFoundException: org.apache.maven.surefire.booter.ForkedBooter
                -->
                <useSystemClassLoader>true</useSystemClassLoader>
                <useManifestOnlyJar>false</useManifestOnlyJar>
            </configuration>
        </plugin>

答案 17 :(得分:1)

您可以使用以下命令。因为你的单元测试需要分叉。关于您在单元测试中使用线程的问题。

mvn test -DforkCount=2

我希望。很有帮助。

答案 18 :(得分:1)

您可以设置Java选项

SET JAVA_OPTS='-Xmx1024m' XX:+UseLoopPredicate

mvn clean install

答案 19 :(得分:1)

我遇到了同样的问题,并通过使用Oracle的Java 8而不是Openjdk的Java 10来解决了

答案 20 :(得分:1)

使用maven surefire 2.21.0,我解决了将reuseForks选项值从 true 更改为 false 的问题:

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

我正在构建的整个配置部分如下:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.21.0</version>
            <configuration>
                <testFailureIgnore>true</testFailureIgnore>
                <skip>false</skip>
                <reuseForks>false</reuseForks>
                <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
                <argLine>-Dfile.encoding=UTF-8</argLine>
                <useSystemClassLoader>false</useSystemClassLoader>
                <includes>
                    <!--Test* classes for the app testing -->
                    <include>**/directory/Test*.java</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>

答案 21 :(得分:1)

我尝试了所有提供的解决方案(分叉,系统加载器,更多内存等。),没有任何效果。

环境:在gitlab ci环境中构建失败,在docker容器中运行了构建。

解决方案: 我们使用2.20.1版中的surefireplugin并升级到2.21.0或更高版本(我们使用2.22.1)解决了该问题。

原因SUREFIRE-1422-surefire使用命令ps,该命令在docker环境中不可用,并导致“崩溃”。此问题已在2.21.0或更高版本中修复。

感谢另一个问题的回答:https://stackoverflow.com/a/50568662/2970422

答案 22 :(得分:1)

使用maven test运行单元测试时,我面临着同样的问题。 尝试更改surefire版本,但它不能正常工作。 最终设法解决如下: 早些时候:(发生问题时): javac来自jdk 1.8 Java指向jdk 1.11中的Java bin 当前:(问题解决后): javac和java都指向jdk 1.8中的垃圾箱

问候 Teja。

答案 23 :(得分:1)

我将surefire插件更新为以下内容,这解决了我的问题:

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
                    <forkCount>1</forkCount>
                    <reuseForks>true</reuseForks>
                    <runOrder>alphabetical</runOrder>
                </configuration>
            </plugin>

答案 24 :(得分:1)

我在Java 8和Spring Boot 5.2.7上遇到了相同的问题(现成的插件已包含在内)。插件版本为默认(2.22.2)。就我而言,问题仅在团队中的某些机器上发生,而在其他机器上,一切都很好。我想这与检测到的maven内核数量有关。

我通过以下设置对其进行了修复:

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

我尝试了许多提议的方法,但对我而言没有任何作用。

此解决方案的唯一缺点是禁用fork的重用,并且测试现在运行缓慢。

答案 25 :(得分:1)

添加配置文件后我可以删除此错误:

<profile>
            <id>surefire-windows-fork-disable</id>
            <activation>
                <os>
                    <family>Windows</family>
                </os>
            </activation>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <configuration>
                                <forkCount>0</forkCount>
                                <useSystemClassLoader>false</useSystemClassLoader>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>

似乎这是一个关于 maven surefire fork 的 windows 问题

答案 26 :(得分:1)

我在Jenkins构建的Ubuntu机器上遇到了这个问题。

/var/log/syslog报告了Out of memory: Kill process 19557 (java) score 207 or sacrifice child

I therefore gave the Ubuntu machine more swap space。从那时起,问题就消失了。

答案 27 :(得分:0)

在运行JAVA = 1.8的Windows 10环境中尝试编译设置为1.7的maven项目遇到了同样的问题。

我通过将java版本从1.7更改为1.8来解决它,如下所示。

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin>

答案 28 :(得分:0)

发生在我身上:如果您的项目依赖于 docker 机器或/和数据库来成功构建,那么请首先检查您的 db 实例是否已启动并且您的 docker 是否也已启动,因为可能有一些单元测试在后台运行.. . 尤其是在启动您的笔记本电脑后检查一下.. 希望可以帮助某人

答案 29 :(得分:0)

我的场景是

  • 我的测试有很多日志输出(我的意思是很多!)
  • Surefire 插件 v2.22.2
  • 该错误仅发生在 IDE 内部,而不是从命令行执行 mvn 命令。
  • 没有任何来自 Surefire 插件的 .dump 文件或来自 Java 二进制文件的传统 hs_err 崩溃文件的迹象。

有两件事一直是我的解决方案(它们是替代方案):

  1. 不要使用分叉:设置 Surefire 插件属性 forkcount = 0
  2. 增加 Surefire 插件属性 forkedProcessExitTimeoutInSeconds 从 30 秒到 300 秒。 plugin documentation 表示如果达到此超时,您将看到错误消息 There was a timeout in the fork。我没有看到这样的错误消息,但它始终如一地解决了增加此超时值的问题。

您可能希望使用解决方案 (2),因为需要分叉。

为什么?

我的理论是,如果有大量日志输出,那么在 fork 关闭时仍然需要进行大量处理(特别是如果您在 IDE 中运行,该 IDE 会捕获输出并可能为其窗口使用内存映射文件内容)。简而言之:在测试完成时,仍有大量文本等待转发到您的 IDE。看来 30 多岁还不够。

这也解释了为什么有些开发人员会看到问题,而有些则不会。测试完成时还剩下多少输出处理可能是CPU功率、磁盘速度等的函数。

如果我在这方面是对的 - 无法证明 - 那么所有建议,如重定向日志输出和降低日志记录级别都是 IMO 治疗症状,而不是原因。

答案 30 :(得分:0)

简单的解决办法: 你应该添加 src/test/resources/logback.xml

<configuration debug="false">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%date{HH:mm:ss.SSS} %highlight(%-5level)
            %gray(%logger{90}) %X{X-ApplicationId} %msg%n
        </pattern>
    </encoder>
</appender>

答案 31 :(得分:0)

我有很多次,对我来说,这几乎总是与“控制台”相关,与实际分叉无关。

简而言之,我的解决方案是:

  • 添加 -B(批处理模式)
  • 添加 JVM 参数 -Djansi.force=true -Djansi.passthrough=true

在给定的项目中,这会系统地失败在新的 Windows 控制台 (cmd.exe) 中

<块引用>

[path_to_jdk]\java.exe -Dmaven.home=[path_to_maven]\apache-maven-3.6.3 -Dclassworlds.conf=[path_to_maven]\bin..\bin\m2.conf -Dmaven.multiModuleProjectDirectory=[path_to_myproject] -Dfile.encoding=UTF-8 -Djansi.force=true -Djansi.passthrough=true -classpath [path_to_maven]\boot\plexus-classworlds-2.6.0.jar org.codehaus.plexus.classworlds.launcher.Launcher 全新安装 -B

这在新的控制台窗口 (cmd.exe) 中总是有效

<块引用>

[path_to_jdk]\java.exe -Dmaven.home=[path_to_maven]\apache-maven-3.6.3 -Dclassworlds.conf=[path_to_maven]\bin..\bin\m2.conf -Dmaven.multiModuleProjectDirectory=[path_to_myproject] -Dfile.encoding=UTF-8 -Djansi.force=true -Djansi.passthrough=true -classpath [path_to_maven]\boot\plexus-classworlds-2.6.0.jar org.codehaus.plexus.classworlds.launcher.Launcher 全新安装 -B

注意这两个命令都有-B(批处理模式应该关闭着色),唯一的区别是

-Djansi.force=true -Djansi.passthrough=true

现在我只需要能够将这些“JVM args”传递给“mvn.cmd”以使其更好。

我猜是这样的:Is there a way to pass jvm args via command line to maven?


一点背景:

自从最新版本的maven(3.x +)以来,我反复遇到这个问题。 我在这里尝试了许多解决方案,有时很幸运,有时没有。

官方文档的这篇文章一直没用:https://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html

但是有常量,当我遇到这个问题时:

  • 始终在本地 Windows 上
  • 总是有大量的控制台输出。
  • 并非团队的所有开发人员都在给定项目上遇到错误
  • Jenkins 构建会通过
  • *IT 测试(故障安全集成测试)中的大量控制台输出

关键的发现是我注意到在 Eclipse 中(无论有没有嵌入式 maven 版本)一个完整的 maven 构建(干净安装)都可以工作。

所以我弄清楚了 Eclipse 使用的是哪个命令(感谢:How do I get the command-line for an Eclipse run configuration?

从那里,我能够确定解决方案是什么。

查看人们所说的其他答案

那里显然有一个错误。无论是在 Maven 中还是在 windows 控制台中,或者在 Jansi 库中,或者在这些组件的集成中。

答案 32 :(得分:0)

在我的测试类中的静态成员变量之后,我遇到了这个错误,该变量称为创建对象的方法(在整个类中的测试用例中使用),并且该方法导致异常。

// Object created inside test class by calling a static getter.
// Exception thrown in getter:
private static Object someObject = SomeObject.getObject(...);

// ... <Object later used in class>

一些修复包括在每个测试用例中重新创建对象并相应地捕获任何异常。或者通过在@BeforeTest方法中初始化对象并确保它正确构建。

答案 33 :(得分:0)

在我的情况下,问题与工作空间路径有关,这段时间很长。所以我做了一个路径重构,这解决了我的问题。

答案 34 :(得分:0)

我在一个应用程序中遇到了同样的问题,该应用程序在运行测试时将大量XML记录到控制台中。我认为问题与测试fork将其控制台日志发送到主Maven线程并输出到屏幕的方式有关。

我通过在测试回退文件中将有问题的类的日志记录设置为WARN来解决此问题。

例如logback-test.xml

<configuration debug="true">
  <include resource="org/springframework/boot/logging/logback/defaults.xml" />
  <include resource="org/springframework/boot/logging/logback/console-appender.xml" />

  <logger name="com.foo.ClassWithLotsOfXmlLogging" level="WARN" />

  <root level="INFO">
    <appender-ref ref="CONSOLE"/>
  </root>
</configuration>

答案 35 :(得分:0)

当我遇到此错误时,由于我的ulimit打开文件(ulimit -n)太低。它(以某种方式)设置为只有256:

% ulimit -n
256

增加限制后错误消失了:

% ulimit -n 3072
% ulimit -n     
3072

您的系统可能不允许将限制设置得那么高。例如,当我尝试使用更大的数字时会发生这种情况:

% ulimit -n 3073
ulimit: setrlimit failed: invalid argument

或者这可能低于您现有的限制,您可能面临不同的根本原因。

答案 36 :(得分:0)

在我的情况下,我忘了在pom中添加依赖项:

      <dependency>
          <groupId>org.aspectj</groupId>
          <artifactId>aspectjweaver</artifactId>
          <version>1.8.5</version>
      </dependency>

只需确保选择正确的版本(至今为1.8.9是最新的)

答案 37 :(得分:0)

我使用的文件夹名称为 test&demo ,因此出现了此问题(VM终止而没有说再见。VM崩溃或调用了System.exit),但是当我将文件夹名称命名为 test_demo 即可解决此问题。(带有“&”符号的Windows操作系统存在此问题。)

将“&”替换为“ _”

此问题可能导致某些特殊符号或文件夹名称中的多余空间。

答案 38 :(得分:0)

我也经历过这种情况 - 但在我的情况下,我为黄瓜编写了一个自定义钩子

public class MappingFormatter implements gherkin.formatter.Formatter {

...

我的一个方法是产生一个Null指针异常,导致surefire退出而不记录错误。

答案 39 :(得分:0)

我遇到的情况类似于Chad's,但是找到了不同的答案。

对于每个the plugin docs,您不能在${...}中使用<argLine>,因为Maven会在surefire插件(或任何其他插件)开始使用之前进行替换。

从2.17版开始,该插件支持@{...}而非${...}进行属性替换。

例如,将其替换

<argLine>XX:MaxPermSize=1024m ${moreArgs}</argLine>

与此

<argLine>XX:MaxPermSize=1024m @{moreArgs}</argLine>

答案 40 :(得分:0)

就我而言,通过设置MAVEN_OPTS来增加内存会有所帮助:

set MAVEN_OPTS=-Xmx1024m

答案 41 :(得分:0)

升级到Java 12之后,我遇到了类似的问题,对我来说,解决方案是更新jacoco版本<jacoco.version>0.8.3</jacoco.version>

答案 42 :(得分:0)

在端口5005上进行远程调试Selenium测试代码时,我也在MacOS上遇到了这个问题。该问题原来是由剩余的surefire-forked-JVM仍在运行引起的。输出到Eclipse IDE终端的日志未显示地址已在使用的根本问题。仅当我在Eclipse实际尝试运行的MacOS终端中运行相同命令时,才会显示日志消息:

/bin/sh -c cd /path/to/your/project/directory && /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/bin/java -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 -jar /path/to/target/surefire/surefirebooter230340673926465933.jar /path/to/target/surefire 2019-06-28T10-50-02_140-jvmRun1 surefire6455775580414993159tmp surefire_02461993428448591420tmp

杀死恶意JVM实例(在“活动监视器”中查找Java进程名称)解决了该问题。顺便说一句,我正在运行surefire插件版本2.21.0,而打开jdk 8(v1.8.0_212)没有任何问题。请注意,所有路径都将特定于您的构建环境以及端口(地址= 5005)。

答案 43 :(得分:0)

对于我来说,这是我的代码调用System.exit(0)。

以下是te文档的摘录:

  

Surefire随时不支持测试或任何引用的调用System.exit()的库。如果这样做,则说明它们与Surefire不兼容,您可能应该向图书馆/供应商提出问题。

答案 44 :(得分:0)

测试中使用的分叉JVM的内存不足。 解决方案是禁用分叉JVM并在主JVM上运行测试以确保您有足够的内存,或者通过args增加分叉的JVM的内存。

在此answer

中查看解决方案

答案 45 :(得分:0)

最近 travis 杀死了测试的执行(没有更改任何相关的内容(以及在开发者机器上成功构建!)),因此 BUILD FAILURE 。 其中一个原因是这个(见@agudian答案):

  

Surefire不支持测试或任何调用System.exit()`

的引用库

(因为测试类确实称为System.exit(-1))。

  1. 使用简单的return语句会有所帮助。

  2. 为了让travis再次开心,我还必须添加@xiaohuo提供的surefire参数(<argLine>)。 (另外,我必须删除-XX:MaxPermSize=256m才能在我的某个桌面上构建)

  3. 只做两件事的一个没有用。

    有关更多背景信息,请阅读When should we call System.exit in Java

答案 46 :(得分:0)

由于完全不同的问题,这也可能发生。例如,在我的情况下,我们的Jenkins构建在执行测试时间歇性地失败。

我通过测试筛选发现System.exit()的任何事件,但没有。{

经过多次挖掘后,我发现这可能会发生,因为JDK错误可能导致这种回归。

JDK-6675699

我仍在努力在我们的构建中进行此修复,将返回并再次更新该线程。

答案 47 :(得分:0)

这可能是由于内存不足造成的。运行mvn时,请确保没有任何应用程序在后台运行。就我而言,Firefox在具有高内存使用率的后台运行。

答案 48 :(得分:0)

这肯定会有效.....

在POM文件中添加以下行并进行构建。

var userStore = new UserStore<ApplicationUser>(context);

答案 49 :(得分:0)

尝试以上所有方法,没有用。以下解决方案对我有用:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
    <argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>

答案 50 :(得分:0)

在Windows(OpenJDK11,Maven 3.6.0,SUREFIRE 3.0.0-M1)上,我找到了根本原因:

# Created at 2018-11-14T14:28:15.629
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000006c7500000, 522190848, 0) failed; error='The paging file is too small for this operation to complete' (DOS error/errno=1455)

,并通过增加分页文件的大小来解决,例如this

答案 51 :(得分:0)

我对这个问题的解决方案是关闭该死的Chrome浏览器,它阻塞了我的计算机的内存

答案 52 :(得分:-1)

可能是因为您在项目中应用了一些更改,并且没有更新所有引用。

在我的情况下,我收到此错误,因为我已在项目中更新了包名,但我忘记更新他们在TestNG.xml文件中的引用。通过纠正它,我解决了这个错误。

答案 53 :(得分:-2)

“由以下引起:java.util.concurrent.ExecutionException:java.lang.RuntimeException:分叉的VM在没有正确说再见的情况下终止.VM崩溃或System.exit被调用?”

如果您使用非兼容版本的java ,则可能会发生此问题。喜欢使用新版本的java而代码支持其他一些版本。

答案 54 :(得分:-6)

  

分叉的虚拟机终止而没有说再见。 VM崩溃或System.exit调用

防止此错误的方法是以管理员身份运行IDE。

答案 55 :(得分:-19)

对我而言,它适用于

mvn clean install -DskipTests -e