Java Maven surefire 找不到 ForkedBooter 类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/53010200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven surefire could not find ForkedBooter class
提问by Sylordis
Recently coming to a new project, I'm trying to compile our source code. Everything worked fine yesterday, but today is another story.
最近来到一个新项目,我正在尝试编译我们的源代码。昨天一切正常,但今天是另一个故事。
Every time I'm running mvn clean install
on a module, once reaching the tests, it crashes into an error:
每次我mvn clean install
在一个模块上运行时,一旦到达测试,它就会崩溃:
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ recorder ---
[INFO] Surefire report directory: /lhome/code/recorder/target/surefire-reports
[INFO] Using configured provider org.apache.maven.surefire.junitcore.JUnitCoreProvider
[INFO] parallel='none', perCoreThreadCount=true, threadCount=0, useUnlimitedThreads=false, threadCountSuites=0, threadCountClasses=0, threadCountMethods=0, parallelOptimized=true
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Error: Could not find or load main class org.apache.maven.surefire.booter.ForkedBooter
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
and later on:
后来:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project recorder: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test failed: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
I'm running on Debian 9(Stretch) 64-bits with OpenJDK 1.8.0_181, Maven3.5.4, working behind my company proxy which I configured in my ~/.m2/settings.xml
.
我在Debian 9(Stretch) 64 位和 OpenJDK 1.8.0_181、Maven3.5.4 上运行,在我在~/.m2/settings.xml
.
A strange thing it that the latest Surefire version is 2.22.1 if I remember correctly. I tried to specify the plugin version, but it does not get updated, otherwise there's no plugin version specification in any POM(parent, grand-parent or this one).
奇怪的是,如果我没记错的话,最新的 Surefire 版本是 2.22.1。我试图指定插件版本,但它没有更新,否则任何POM(父、祖父或这个)中都没有插件版本规范。
I managed to force Maven to change the Surefire version to the latest, but now it's even worse:
我设法强制 Maven 将 Surefire 版本更改为最新版本,但现在情况更糟:
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[...]
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project recorder: There are test failures.
[ERROR]
[ERROR] Please refer to /lhome/code/recorder/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd /lhome/code/recorder/ && /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java '-javaagent:/lhome1/johndoe/.m2/repository/org/jacoco/org.jacoco.agent/0.7.4.201502262128/org.jacoco.agent-0.7.4.201502262128-runt ime.jar=destfile=/lhome/code/recorder/target/jacoco.exec,append=true,includes=esa/*,excludes=**/api/**/*.class' -jar /lhome/code/recorder/target/surefire/surefirebooter7426165516226884923.jar /lhome/code/recorder/target/surefire 2018-10-26T16-16-12_829-jvmRun1 surefire1721866559613511529tmp surefire_023400764142672144tmp
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd /lhome/code/recorder/ && /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java '-javaagent:/lhome1/johndoe/.m2/repository/org/jacoco/org.jacoco.agent/0.7.4.201502262128/org.jacoco.agent-0.7.4.201502262128-runt ime.jar=destfile=/lhome/code/recorder/target/jacoco.exec,append=true,includes=esa/*,excludes=**/api/**/*.class' -jar /lhome/code/recorder/target/surefire/surefirebooter7426165516226884923.jar /lhome/code/recorder/target/surefire 2018-10-26T16-16-12_829-jvmRun1 surefire1721866559613511529tmp surefire_023400764142672144tmp
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:669)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:282)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:245)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1183)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1011)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:857)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
[ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
[ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
[ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:954)
[ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
[ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
采纳答案by Erich Schubert
To fix it (in 2018), update your openjdk to the latest version, at least 8u191-b12.In case this issue reappears in 2020, it is likely that the default behavior of openjdk was changed, and you will then need to update the maven surefire plugin.
要修复它(2018 年),请将您的 openjdk 更新到最新版本,至少为 8u191-b12。如果这个问题在 2020 年再次出现,很可能是 openjdk 的默认行为发生了变化,然后您需要更新 maven surefire 插件。
This was a now fixedbug in the openjdk-8 package(behaviour deviates from upstream significantly without need; missing the upstream patch to revert back to disabling a security check) that you just upgraded to. But it is also a bug in the surefire plugin, SUREFIRE-1588, supposedly fixed in surefire 3.0.0-M1: it apparently is using absolute paths in a place where Java will in the future only allow relative path names (and Debian activated the future behavior already).
这是您刚刚升级到的 openjdk-8 包中的一个现已修复的错误(行为明显偏离上游而无需;缺少上游补丁以恢复禁用安全检查)。但它也是surefire插件中的一个错误, SUREFIRE-1588,据说在surefire3.0.0-M1中修复:它显然在Java将来只允许相对路径名的地方使用绝对路径(并且Debian激活了未来的行为已经)。
The package version 8u181-b13-2 states:
软件包版本 8u181-b13-2 说明:
- Apply patches from 8u191-b12 security update.
- 应用 8u191-b12 安全更新中的补丁。
Note that 191-b12 != 181-b13. The 191-b12 security patches were just out a few days ago, and apparently the maintainers wanted to get them to you fast. Updating completely to 191-b12 will likely need additional testing (well, so should have this upload, apparently).
请注意,191-b12 != 181-b13。191-b12 安全补丁几天前刚刚发布,显然维护人员希望尽快将它们提供给您。完全更新到 191-b12 可能需要额外的测试(好吧,显然应该有这个上传)。
There had been several workaounds:
有几种解决方法:
- You can install the previous packagefrom snapshots.d.oinstead. After downgrading, you can forbid the broken version (if you are using aptitude and not
apt
) usingsudo aptitude forbid-version openjdk-8-jre-headless
. For regular "apt" I didn't see a similar forbid mechanism, so you would likely need to use apt pinning to prevent this upgrade from being reinstalled (or you just keep on downgrading again, I hope this will be resolved soon). - According to bug tracking, setting the property
-Djdk.net.URLClassPath.disableClassPathURLCheck=true
with any of the usual methods (e.g.,JAVA_FLAGS
) should also help. But I have not verified this myself. You can apparently even add the workaround to~/.m2/settings.xml
to get it enabled for all your Maven builds easily.
- 你可以从 snapshots.do安装以前的包。降级后,您可以
apt
使用sudo aptitude forbid-version openjdk-8-jre-headless
. 对于常规的“apt”,我没有看到类似的禁止机制,因此您可能需要使用 apt 固定来防止重新安装此升级(或者您只是继续降级,我希望这将很快得到解决)。 - 根据错误跟踪,
-Djdk.net.URLClassPath.disableClassPathURLCheck=true
使用任何常用方法(例如,JAVA_FLAGS
)设置属性也应该有所帮助。但我自己没有验证过。显然,您甚至可以添加解决方法,~/.m2/settings.xml
以轻松为您的所有 Maven 构建启用它。
As you can see, bug tracking works, the issue was narrowed down, and a fixed package is available and a new version of the surefire plugin will come soon!
如您所见,错误跟踪有效,问题已缩小,并且有一个固定包可用,新版本的万无一失插件即将推出!
回答by user3090935
I found this workaroundand fixed my tests: configure the maven-surefire-plugin
not to use the system classloader.
我找到了这个解决方法并修复了我的测试:配置maven-surefire-plugin
不使用系统类加载器。
回答by brunobastosg
I had this issue in my GitLab CI build, which was using maven:3.5.4-jdk-8
Docker image.
我在使用maven:3.5.4-jdk-8
Docker 映像的GitLab CI 构建中遇到了这个问题。
Changing it to maven:3.5.4-jdk-8-alpine
fixed the problem.
更改它以maven:3.5.4-jdk-8-alpine
解决问题。
回答by Simon Diemert
For those searching for an answer related to Docker Maven: 3.5.x-jdk-8 on GitLab CI, see this GitHub issue.
对于那些在 GitLab CI 上搜索与 Docker Maven:3.5.x-jdk-8 相关的答案的人,请参阅此 GitHub 问题。
It appears a 3.5.4-jdk-8
image resulted in upgrade to a minor Java version which somehow affects Surefire's forking mechanism.
似乎3.5.4-jdk-8
图像导致升级到次要 Java 版本,这以某种方式影响了 Surefire 的分叉机制。
Rolling back to 3.5.3-jdk-8
image fixed this for me on my GitLab CI server building Java 1.8 code with Surefire 2.20.1.
3.5.3-jdk-8
在使用 Surefire 2.20.1 构建 Java 1.8 代码的 GitLab CI 服务器上,回滚到图像为我修复了这个问题。
回答by amdev
If like me you have issues in your pipeline (for me it's in GitLab, but whatever) and if you are using a Maven JDK 8 Docker image.
如果像我一样,您的管道中有问题(对我来说,它在 GitLab 中,但无论如何),并且您使用的是 Maven JDK 8 Docker 映像。
You can replace
你可以更换
image: maven:3.5.4-jdk-8
by the last working build
通过最后一个工作构建
image: maven@sha256:b37da91062d450f3c11c619187f0207bbb497fc89d265a46bbc6dc5f17c02a2b
回答by Michael
I have another workaround. Set the environment variable _JAVA_OPTIONS. I've used this for our TeamCity build agents and now our builds run fine.
我有另一种解决方法。设置环境变量_JAVA_OPTIONS。我已经将它用于我们的 TeamCity 构建代理,现在我们的构建运行良好。
_JAVA_OPTIONS=-Djdk.net.URLClassPath.disableClassPathURLCheck=true
回答by Markoorn
Set useSystemClassloader to false:
将 useSystemClassloader 设置为 false:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
If you're not inheriting from a parent which has version defined for you (such as the Spring Boot starter) you'll need to define that as well.
如果您不是从为您定义了版本的父级(例如 Spring Boot starter)继承,您还需要定义它。
回答by farid g.
The suggestion above to set the property "-Djdk.net.URLClassPath.disableClassPathURLCheck=true"did NOT work for me, but setting the following does work OK:
上面设置属性“-Djdk.net.URLClassPath.disableClassPathURLCheck=true”的建议对我不起作用,但设置以下内容确实可以:
-DforkCount=0
回答by Jesse Glick
I posted a more targeted variant of one of the above workarounds in JIRA. Add to ~/.m2/settings.xml
:
我在 JIRA 中发布了上述解决方法之一的更有针对性的变体。添加到~/.m2/settings.xml
:
<profile>
<id>SUREFIRE-1588</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
</properties>
</profile>
回答by Arunkumar Arjunan
I followed this link https://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.htmland added the below plugin in pom.xml and it worked,
我按照这个链接https://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html并在 pom.xml 中添加了以下插件并且它工作了,
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>