java.lang.OutOfMemoryError:Maven中的Java堆空间

zjf*_*fdu 119 java out-of-memory maven

当我运行maven test时,会发生java.lang.OutOfMemoryError.我谷歌它的解决方案,并尝试过export MAVEN_OPTS=-Xmx1024m,但它没有奏效.任何人都知道这个问题的其他解决方案,BTW我正在使用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

Pas*_*ent 155

当我运行maven test时,会发生java.lang.OutOfMemoryError.我谷歌它的解决方案,并试图导出MAVEN_OPTS = -Xmx1024m,但它没有用.

Xmx使用选项设置MAVEN_OPTS确实有效,它确实配置了用于启动Maven的JVM.话虽这么说,maven-surefire-plugin 默认会激活一个新的JVM,MAVEN_OPTS因此你不会被传递.

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

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

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

<configuration>
  <argLine>-Xmx1024m</argLine>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我必须说我倾向于同意斯蒂芬在这里,你的测试之一很可能出现问题,我不确定提供更多内存是解决问题(隐藏?)的正确解决方案.

参考

  • `forkMode`已被弃用:http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#forkMode (3认同)

use*_*048 61

对于那些刚接触Maven的人(像我一样),这是整个配置,它位于你的pom的构建部分.干杯.

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19</version>
        <configuration>
            <argLine>-Xmx1024m</argLine>
        </configuration>
      </plugin>
    </plugins>
  </build>
Run Code Online (Sandbox Code Playgroud)


Ste*_*n C 12

可能是问题出在你要求Maven运行的单元测试中.

因此,摆弄堆大小是错误的方法.相反,您应该查看导致OOME的单元测试,并尝试确定它是单元测试的错误还是它正在测试的代码.

首先查看堆栈跟踪.如果没有,请mvn ... test使用该-e选项再次运行.

  • @zjffdu - 你完全错过了我的观点!添加"-e"的目的不是为了使测试工作.这是为了找出它们不起作用的原因. (2认同)
  • 我在运行GWT测试用例时遇到了这个问题,它模拟了一个完整的浏览器环境.有时可以增加堆大小. (2认同)
  • @djjeck - 有时是的。但我认为大多数时候这不是正确的解决方案。 (2认同)

Max*_*ger 8

为了暂时解决这个问题,我发现以下是最快的方法:

export JAVA_TOOL_OPTIONS="-Xmx1024m -Xms1024m"
Run Code Online (Sandbox Code Playgroud)


Ins*_*ein 7

正如最上面的答案中提到的,由于 Surefire 正在创建一个新的 JVM 来运行您的测试,因此您希望将其传递-Xmx1024m给新的 JVM 而不是您启动的 JVM mvn test

只是想补充一点,您可以在命令中执行此操作,例如

mvn test -DargLine="-Xmx1024m"
Run Code Online (Sandbox Code Playgroud)

它与在 pom.xml 中的 Surefire 插件配置中添加 JVM 选项具有相同的效果:

<configuration>
  <argLine>-Xmx1024m</argLine>
</configuration>
Run Code Online (Sandbox Code Playgroud)


Min*_*ang 6

我通过两种方式解决了这个问题:

  1. 在pom.xml中添加此配置

    <configuration><argLine>-Xmx1024m</argLine></configuration>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 切换到使用JDK 1.7而不是1.6


Nar*_*chu 5

为了解决Maven中的java.lang.OutOfMemoryError: Java heap space,尝试在pom中配置以下配置

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>${maven-surefire-plugin.version}</version>
     <configuration>
        <verbose>true</verbose>
        <fork>true</fork>
        <argLine>-XX:MaxPermSize=500M</argLine>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)