本文介绍了java.lang.OutOfMemoryError:Maven 中的 Java 堆空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行 maven 测试时,java.lang.OutOfMemoryError 发生.我在 google 上搜索了解决方案,并尝试 export MAVEN_OPTS=-Xmx1024m,但没有奏效.有人知道这个问题的其他解决方案吗?我正在使用 Maven 3.0

运行mvn test -e

时将错误信息粘贴到这里失败的测试:警告(junit.framework.TestSuite$1)testDefaultPigJob_1(com.snda.dw.pig.impl.DefaultPigJobLocalTest)testDefaultPigJob_2(com.snda.dw.pig.impl.DefaultPigJobLocalTest)测试运行:11,失败:3,错误:0,跳过:010/11/01 13:37:18 INFO executionengine.HExecutionEngine:连接到 hadoop fi文件系统位于:file:///[信息] ------------------------------------------------------------------------[信息] 构建失败[信息] ------------------------------------------------------------------------[信息] 总时间:30.063s[信息] 完成时间:2010 年 11 月 1 日星期一 13:37:18 PDT[INFO] 最终内存:3M/6M[信息] ------------------------------------------------------------------------[错误] 无法执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.5:test (default-test) on project dw.pig: 有测试失败.[错误][ERROR] 请参考 E:CodeJavaworkspacedw.pigargetsurefire-reportsr 个人测试结果.[错误] -> [帮助 1]org.apache.maven.lifecycle.LifecycleExecutionException:无法执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.5:test (default-test) on projectdw.pig:有测试失败.请参考 E:CodeJavaworkspacedw.pigargetsurefire-reports 中的个别测试结果.在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:199)在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:140)在 org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)在 org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)在 org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)在 org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleeStarter.java:161)在 org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:314)在 org.apache.maven.DefaultMaven.execute(DefaultMaven.java:151)在 org.apache.maven.cli.MavenCli.execute(MavenCli.java:445)在 org.apache.maven.cli.MavenCli.doMain(MavenCli.java:168)在 org.apache.maven.cli.MavenCli.main(MavenCli.java:132)在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.爪哇:39)在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)在 java.lang.reflect.Method.invoke(Method.java:597)在 org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)在 org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav答:230)在 org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)在 org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)引起:org.apache.maven.plugin.MojoFailureException:有测试失败.请参考 E:CodeJavaworkspacedw.pigargetsurefire-reports 中的个别测试结果.在 org.apache.maven.plugin.surefire.SurefirePlugin.execute(SurefirePlugin.java:629)在 org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(默认BuildPluginManager.java:107)在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:195)... 19 更多[错误][错误] 使用 -X 开关重新运行 Maven 以启用完整的调试日志记录.[错误][ERROR] 有关错误和可能的解决方案的更多信息,请阅读d 以下文章:[错误] [帮助 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureExc
解决方案

使用 MAVEN_OPTS 设置 Xmx 选项确实有效,它确实配置了用于启动 Maven 的 JVM.话虽如此,maven-surefire-plugin forks 默认情况下是一个新的 JVM,因此不会通过您的 MAVEN_OPTS.

要配置 maven-surefire-plugin 使用的 JVM 的大小,您必须:

  • 更改forkModenever(这不是一个好主意,因为 Maven 不会与测试隔离)~或~
  • 使用 argLine 参数(正确的方式):

在后一种情况下,是这样的:

<argLine>-Xmx1024m</argLine></配置>

但是我不得不说我倾向于同意斯蒂芬的观点,你的一个测试很可能有问题,我不确定给予更多内存是正确的解决方案解决"(隐藏?)你的问题.

参考资料

When I run maven test, java.lang.OutOfMemoryError happens. I googled it for solutions and have tried to export MAVEN_OPTS=-Xmx1024m, but it did not work.Anyone know other solutions for this problem? I am using maven 3.0

Paste the error message here when run mvn test -e

Failed tests:
  warning(junit.framework.TestSuite$1)
  testDefaultPigJob_1(com.snda.dw.pig.impl.DefaultPigJobLocalTest)
  testDefaultPigJob_2(com.snda.dw.pig.impl.DefaultPigJobLocalTest)

Tests run: 11, Failures: 3, Errors: 0, Skipped: 0

10/11/01 13:37:18 INFO executionengine.HExecutionEngine: Connecting to hadoop fi
le system at: file:///
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30.063s
[INFO] Finished at: Mon Nov 01 13:37:18 PDT 2010
[INFO] Final Memory: 3M/6M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.
5:test (default-test) on project dw.pig: There are test failures.
[ERROR]
[ERROR] Please refer to E:CodeJavaworkspacedw.pig	argetsurefire-reports fo
r the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
rg.apache.maven.plugins:maven-surefire-plugin:2.5:test (default-test) on project
 dw.pig: There are test failures.

Please refer to E:CodeJavaworkspacedw.pig	argetsurefire-reports for the in
dividual test results.
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:199)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:148)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:140)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBu
ild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
eStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:314)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:151)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:445)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:168)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:132)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
cher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
a:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
uncher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
352)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures
.

Please refer to E:CodeJavaworkspacedw.pig	argetsurefire-reports for the in
dividual test results.
        at org.apache.maven.plugin.surefire.SurefirePlugin.execute(SurefirePlugi
n.java:629)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(Default
BuildPluginManager.java:107)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:195)
        ... 19 more
[ERROR]
[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 rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureExc
解决方案

Setting the Xmx options using MAVEN_OPTS does work, it does configure the JVM used to start Maven. That being said, the maven-surefire-plugin forks a new JVM by default, and your MAVEN_OPTS are thus not passed.

To configure the sizing of the JVM used by the maven-surefire-plugin, you would either have to:

  • change the forkMode to never (which is be a not so good idea because Maven won't be isolated from the test) ~or~
  • use the argLine parameter (the right way):

In the later case, something like this:

<configuration>
  <argLine>-Xmx1024m</argLine>
</configuration>

But I have to say that I tend to agree with Stephen here, there is very likely something wrong with one of your test and I'm not sure that giving more memory is the right solution to "solve" (hide?) your problem.

References

这篇关于java.lang.OutOfMemoryError:Maven 中的 Java 堆空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 06:09