java.lang.OutOfMemoryError : Java heap space in Maven

标签 java maven out-of-memory

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

运行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:\Code\Java\workspace\dw.pig\target\surefire-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:\Code\Java\workspace\dw.pig\target\surefire-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:\Code\Java\workspace\dw.pig\target\surefire-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

最佳答案

When I run maven test, java.lang.OutOfMemoryError happens. I google it for solutions and have tried to export MAVEN_OPTS=-Xmx1024m, but it did not work.

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

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

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

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

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

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

引用文献

关于java.lang.OutOfMemoryError : Java heap space in Maven,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4066424/

相关文章:

tomcat - 我如何在两个不同的环境中使用 maven tomcat 插件?

maven - gradle init不适用于pom.xml中的某些插件

eclipse - 生命周期配置未涵盖插件执行

performance - 更高效的查询以避免 Hive 中的 OutOfMemoryError

剩余大量内存时出现 java.lang.OutOfMemoryError (94GB/200GB Xmx)

java - 如何让 RethinkDB 在发生新插入时调用 java 函数?

java - 不确定为什么我的代码给出 "Illegal Format Conversion Exception"错误?

java - 我需要规范化这个 MySQL 数据库吗?

java - 背包算法,大容量

java - 获取单个 ScrollableResults 行