代码之家  ›  专栏  ›  技术社区  ›  zjffdu

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

  •  109
  • zjffdu  · 技术社区  · 15 年前

    export MAVEN_OPTS=-Xmx1024m ,但没有成功。 任何人都知道这个问题的其他解决方案,顺便说一句,我正在使用maven 3.0

    提前谢谢

    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
    
    7 回复  |  直到 15 年前
        1
  •  155
  •   Pascal Thivent    15 年前

    当我运行maven test时,会发生java.lang.OutOfMemoryError。我用google搜索解决方案,并尝试导出MAVEN_OPTS=-Xmx1024m,但没有成功。

    Xmx 选项使用 MAVEN_OPTS 它确实配置了用于启动Maven的JVM。也就是说,maven surefire插件 forks 默认情况下是一个新的JVM,并且 因此没有通过。

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

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

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

        2
  •  62
  •   Mohamed Taher Alrefaie    10 年前

    对于那些新加入Maven的人(比如我),这里是pom的build部分中的整个配置。干杯。

    <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>
    
        3
  •  12
  •   Stephen C    9 年前

    很可能问题出在您让Maven运行的某个单元测试中。

    因此,修改堆大小是错误的方法。相反,您应该查看导致OOME的单元测试,并试图找出它是单元测试的错误还是正在测试的代码。

    mvn ... test 再次与 -e

        4
  •  8
  •   Max Hohenegger    9 年前

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

    export JAVA_TOOL_OPTIONS="-Xmx1024m -Xms1024m"
    
        5
  •  6
  •   Minh Dang    12 年前

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

      <configuration><argLine>-Xmx1024m</argLine></configuration>
      
    2. 切换到used JDK 1.7而不是1.6

        6
  •  1
  •   Narayan Yerrabachu    8 年前

    为了在Maven中解析java.lang.OutOfMemoryError:java堆空间,请尝试在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>
    
        7
  •  -2
  •   e2rabi    9 年前

    不仅仅是堆内存。还可以增加perm size来解决maven中的异常,在环境变量中使用这些变量。

    variable name: MAVEN_OPTS
    variable value: -Xmx512m -XX:MaxPermSize=256m
    

    export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=500m"