Maven 内存不足构建失败 [英] Maven Out of Memory Build Failure

查看:46
本文介绍了Maven 内存不足构建失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

截至今天,我的 Maven 编译失败.

[INFO] [ERROR] 意外[信息] java.lang.OutOfMemoryError:Java 堆空间[信息] 在 java.util.Arrays.copyOfRange(Arrays.java:2694)[信息] 在 java.lang.String.(String.java:203)[信息] 在 java.lang.String.substring(String.java:1877)

<块引用>

[错误] 内存不足;要增加内存量,请使用 -Xmx启动时的标志(java -Xmx128M ...)

截至昨天,我已成功运行了 Maven 编译.

截至今天,我刚刚将堆增加到 3 GB.另外,我只更改了 2-3 行小代码,所以我不明白这个内存不足"错误.

vagrant@dev:/vagrant/workspace$ echo $MAVEN_OPTS-Xms1024m -Xmx3000m -Dmaven.surefire.debug=-Xmx3000m

我通过更改我失败的模块的 pom.xml 来尝试海报的评论.但我遇到了同样的 maven 构建错误.

 <插件><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><配置><来源>1.5</来源><目标>1.5</目标><fork>true</fork><meminitial>1024m</meminitial><maxmem>2024m</maxmem></配置></插件>

解决方案

你说的是哪种网络"模块?是简单的战争,有包装类型的战争吗?

如果您没有使用 Google 的网络工具包 (GWT),那么您不需要提供任何 gwt.extraJvmArgs

分叉编译过程可能不是最好的主意,因为它会启动一个完全忽略MAVEN_OPTS的第二个过程,从而使分析变得更加困难.

所以我会尝试通过设置 MAVEN_OPTS 来增加 Xmx

export MAVEN_OPTS="-Xmx3000m"

并且不要将编译器分叉到不同的进程

<groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><配置><来源>1.5</来源><目标>1.5</目标></配置></插件>

增加 -XX:MaxPermSize=512m 不应该是必需的,因为如果永久大小是问题的原因,那么我会期望错误 java.lang.OutOfMemoryError: PermGen space

如果这不能解决您的问题,那么您可以通过添加 -XX:+HeapDumpOnOutOfMemoryError 创建堆转储以供进一步分析.此外,您可以在编译运行时使用 java bin 目录中的 jconsole.exe 连接到 jvm,并查看 jvm 的堆内部发生了什么.

我想到的另一个想法(可能是个愚蠢的想法),您的机器内存是否足够?定义内存大小很好,但是如果您的主机只有 4GB,那么您可能会遇到 Java 无法使用定义的内存的问题,因为它已被操作系统、Java、MS-Office 使用......

As of today, my maven compile fails.

[INFO] [ERROR] Unexpected
[INFO] java.lang.OutOfMemoryError: Java heap space
[INFO]  at java.util.Arrays.copyOfRange(Arrays.java:2694)
[INFO]  at java.lang.String.<init>(String.java:203)
[INFO]  at java.lang.String.substring(String.java:1877)

[ERROR] Out of memory; to increase the amount of memory, use the -Xmx flag at startup (java -Xmx128M ...)

As of yesterday I had successfully run a maven compile.

As of today, I just bumped up my heap to 3 GB. Also, I only changed 2-3 minor lines of code, so I don't understand this 'out of memory' error.

vagrant@dev:/vagrant/workspace$ echo $MAVEN_OPTS
-Xms1024m -Xmx3000m -Dmaven.surefire.debug=-Xmx3000m

EDIT: I tried the poster's comment by changing my failed module's pom.xml. But I got the same maven build error.

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.5</source>
            <target>1.5</target>
            <fork>true</fork>
            <meminitial>1024m</meminitial>
            <maxmem>2024m</maxmem>
       </configuration>
    </plugin>

解决方案

What kind of 'web' module are you talking about? Is it a simple war and has packaging type war?

If you are not using Google's web toolkit (GWT) then you don't need to provide any gwt.extraJvmArgs

Forking the compile process might be not the best idea, because it starts a second process which ignores MAVEN_OPTS altogether, thus making analysis more difficult.

So I would try to increase the Xmx by setting the MAVEN_OPTS

export MAVEN_OPTS="-Xmx3000m"

And don't fork the compiler to a different process

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.5</source>
        <target>1.5</target>
   </configuration>
</plugin>

Increasing -XX:MaxPermSize=512m should not be required because if perm size is the reason of the problem, then I would expect the error java.lang.OutOfMemoryError: PermGen space

If that does not solve your problem, then you can create heap dumps for further analysis by adding -XX:+HeapDumpOnOutOfMemoryError. Additionally, you can use jconsole.exe in your java bin directory to connect to the jvm while the compilation is running and see what is going on inside the jvm's heap.

Another Idea (may be a stupid one) which came up to me, do you have enough RAM inside your machine? Defining the memory size is nice, but if your host has only 4GB and then you might have the problem that Java is not able to use the defined Memory because it is already used by the OS, Java, MS-Office...

这篇关于Maven 内存不足构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆