请帮我解决这个问题。我不太明白日志中的错误是什么意思。

[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

当前回答

Surefire FAQ的这一部分可以帮助你:

Surefire fails with the message "The forked VM terminated without properly saying goodbye" Surefire does not support tests or any referenced libraries calling System.exit() at any time. If they do so, they are incompatible with surefire and you should probably file an issue with the library/vendor. Alternatively the forked VM could also crash for a number of reasons, which can also make this issue happen. Look for the classical "hs_err*" files indicating VM crashes or examine the log output from running maven when the tests execute. Some "extraordinary" output from crashing processes may be dumped to the console/log. If this happens on a CI environment and only after some time runs there is a fair chance your test suite is leaking some kind of OS-level resource that makes things worse for every run. Regular os-level monitoring tools may give you some indication.

其他回答

Surefire FAQ的这一部分可以帮助你:

Surefire fails with the message "The forked VM terminated without properly saying goodbye" Surefire does not support tests or any referenced libraries calling System.exit() at any time. If they do so, they are incompatible with surefire and you should probably file an issue with the library/vendor. Alternatively the forked VM could also crash for a number of reasons, which can also make this issue happen. Look for the classical "hs_err*" files indicating VM crashes or examine the log output from running maven when the tests execute. Some "extraordinary" output from crashing processes may be dumped to the console/log. If this happens on a CI environment and only after some time runs there is a fair chance your test suite is leaking some kind of OS-level resource that makes things worse for every run. Regular os-level monitoring tools may give you some indication.

简单的解决方案: 您应该添加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>

我的设想是

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

对我来说,有两件事一直是解决方案(它们是替代方案):

不使用fork:设置Surefire插件属性forkcount = 0。 增加Surefire插件属性 forkedProcessExitTimeoutInSeconds从30秒变成300秒。插件文档说,如果这个超时被击中,你会看到错误消息有一个超时在fork。我没有看到这样的错误消息,但是它一直在修复这个问题以增加这个超时值。

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

Why?

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

这也解释了为什么有些开发者能够发现问题,而有些开发者却不能。在测试结束时,剩下多少输出处理可能是cpu功率、磁盘速度等的函数。

如果我在这一点上是正确的-不能证明它-那么所有的建议,如重定向日志输出和降低日志级别都是IMO处理症状,而不是原因。

我在MacOS上远程调试端口5005上的Selenium测试代码时也遇到了这个问题。这个问题原来是由一个仍然运行的剩余的surefire-fork jvm引起的。Eclipse IDE终端的日志输出没有显示底层问题“Address already in use”。只有当我在MacOS终端上运行Eclipse实际试图运行的相同命令时,才会显示日志消息:

/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实例(在Activity Monitor中查找java进程名)解决了这个问题。顺便说一下,我正在运行surefire插件版本2.21.0,与开放jdk 8 (v1.8.0_212)没有问题。注意,所有路径都将特定于您的构建环境,可能还有端口(address=5005)。

我也遇到了同样的问题,并添加了如下内容:

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

整个plugin元素是:

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