簡體   English   中英

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

[英]java.lang.OutOfMemoryError: Java heap space in Maven

當我運行 maven 測試時,會發生java.lang.OutOfMemoryError 我在export MAVEN_OPTS=-Xmx1024m搜索了解決方案,並嘗試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

當我運行 maven 測試時,會發生 java.lang.OutOfMemoryError。 我在谷歌上搜索解決方案並嘗試導出 MAVEN_OPTS=-Xmx1024m,但沒有奏效。

使用MAVEN_OPTS設置Xmx選項確實有效,它確實配置了用於啟動 Maven 的 JVM。 MAVEN_OPTS雖如此,默認情況下 maven-surefire-plugin 會派生一個新的 JVM,因此不會通過您的MAVEN_OPTS

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

  • forkMode更改為never (這不是一個好主意,因為 Maven 不會與測試隔離)~或~
  • 使用argLine參數(正確的方式):

在后一種情況下,是這樣的:

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

我不得不說,我傾向於同意斯蒂芬的觀點,您的一項測試很可能有問題,我不確定提供更多內存是“解決”(隱藏?)您的問題的正確解決方案。

參考文獻

對於 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>

問題很可能出在您要求 Maven 運行的單元測試之一中。

因此,擺弄堆大小是錯誤的方法。 相反,您應該查看導致 OOME 的單元測試,並試圖找出是單元測試的錯誤還是它正在測試的代碼的錯誤。

首先查看堆棧跟蹤。 如果沒有,請使用-e選項再次運行mvn ... test

為了暫時解決這個問題,我發現以下是最快的方法:

export JAVA_TOOL_OPTIONS="-Xmx1024m -Xms1024m"

我已經通過兩種方式解決了這個問題:

  1. 在 pom.xml 中添加這個配置

    <configuration><argLine>-Xmx1024m</argLine></configuration>
  2. 切換到使用的 JDK 1.7 而不是 1.6

為了解決java.lang.OutOfMemoryError: Java heap space in Maven,嘗試在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>

正如上面的回答中提到的,由於 Surefire 正在創建一個新的 JVM 來運行您的測試,您希望將-Xmx1024m傳遞給新的 JVM,而不是您啟動mvn test的 JVM。

只是想補充一點,您可以在命令中執行此操作,例如

mvn test -DargLine="-Xmx1024m"

它與在 pom.xml 中的 Surefire 插件的配置中添加 JVM 選項具有等效的效果:

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

不僅是堆內存。 還增加 perm 大小以解決 maven 中的異常在環境變量中使用這些變量。

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

示例:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM