Maven 抛出“java.lang.OutOfMemoryError”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1920059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 01:26:07  来源:igfitidea点击:

Maven throws "java.lang.OutOfMemoryError"

javamaven-2out-of-memory

提问by user124858

I'm compiling an open source project with "mvn install" but ended up with java.lang.OutOfMemoryError: Java heap space. I tried to execute java -Xmx256mbut the output was java synopsis which indicated it's an invalid command.

我正在使用“mvn install”编译一个开源项目,但最终以java.lang.OutOfMemoryError: Java heap space. 我试图执行,java -Xmx256m但输出是 java 概要,表明它是一个无效的命令。

I'm using jdk1.5.0_08, any ideas why this is happening?

我正在使用jdk1.5.0_08,任何想法为什么会发生这种情况?

Thanks,

谢谢,

采纳答案by cletus

Set the environment variable:

设置环境变量:

MAVEN_OPTS="-Xmx512m"

回答by Andriy Plokhotnyuk

It depends on which JVM instance require more memory. As example, if tests are forked (by default), and fails due OutOfMemoryError then try configure plugin which launching them:

这取决于哪个 JVM 实例需要更多内存。例如,如果测试是分叉的(默认情况下),并且由于 OutOfMemoryError 失败,那么尝试配置启动它们的插件:

        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <argLine>-Xmx1024m</argLine>
            </configuration>
        </plugin>

回答by Matus

I experienced the same problem. According to this linkit might help to change jvm implementation - this can be done by setting JAVA_HOME system variable.

我遇到了同样的问题。根据此链接,它可能有助于更改 jvm 实现 - 这可以通过设置 JAVA_HOME 系统变量来完成。

Try for example in the link mentioned ibm jvm or oracle jrockit:

例如在提到 ibm jvm 或 oracle jrockit 的链接中尝试:

SET JAVA_HOME=C:\bea10\jrockit160_22
mvn install

回答by msuresham

Not only heap memory. You have to increase perm size also to resolve that exception in maven use these variables in environment variable.

不仅是堆内存。您还必须增加 perm 大小以解决 maven 中的异常,在环境变量中使用这些变量。

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

变量名:MAVEN_OPTS
变量值:-Xmx512m -XX:MaxPermSize=256m

回答by user666

Alternatively use set MAVEN_OPTS="-XX:MaxPermSize=256m"while running from command prompt.

或者set MAVEN_OPTS="-XX:MaxPermSize=256m"在从命令提示符运行时使用。

回答by Abdourahmane FALL

Try to change or update your Maven install. I had this problem but I solved it by upgrading Maven (3.0.5 to 3.3.3).

尝试更改或更新您的 Maven 安装。我遇到了这个问题,但我通过升级 Maven(3.0.5 到 3.3.3)解决了它。

回答by 4lberto

Sometimes, if you use other programs inside maven, like in integration tests or Surefire, the MAVEN_OPTS is not enough. Apart from MAVEN_OPTS, try to use JAVA_TOOL_OPTIONS. This did the trick for me in Maven when running some integration tests:

有时,如果您在 maven 中使用其他程序,例如在集成测试或 Surefire 中,MAVEN_OPTS 是不够的。除了 MAVEN_OPTS,尝试使用 JAVA_TOOL_OPTIONS。在 Maven 中运行一些集成测试时,这对我有用:

export JAVA_TOOL_OPTIONS="-Xmx2048m -XX:MaxPermSize=1024m -Xms2048m"

Reference: osx maven running tests Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"

参考: osx maven 运行测试异常:从线程“main”中的 UncaughtExceptionHandler 抛出的 java.lang.OutOfMemoryError

回答by Lucas Pires

I always use this with my shell on ubuntu:

我总是在 ubuntu 上用我的 shell 来使用它:

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

回答by hahakubile

on a Unix-like system:

在类 Unix 系统上:

export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=512m"

OutOfMemoryError

内存不足错误