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

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

问题描述

截止到今天,我的maven编译失败.

[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)

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

截止到昨天,我已经成功运行了Maven编译.

截止到今天,我刚刚将堆增加到 3 GB .另外,我只更改了2-3个较小的代码行,所以我不理解此内存不足"错误.

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

我通过更改失败模块的pom.xml来尝试张贴者的评论.但是我遇到了同样的Maven构建错误.

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

解决方案

您在谈论哪种网络"模块? 这是一场简单的战争,有包装式战争吗?

如果您不使用Google的网络工具包(GWT),则无需提供任何gwt.extraJvmArgs

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

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

export MAVEN_OPTS="-Xmx3000m"

不要将编译器派生到其他进程

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

不需要增加-XX:MaxPermSize=512m,因为如果烫发大小是问题的原因,那么我预计会出现错误java.lang.OutOfMemoryError: PermGen space

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

我想到了另一个想法(可能是一个愚蠢的想法),您的计算机内部是否有足够的RAM?定义内存大小是不错的选择,但是如果您的主机只有4GB,那么您可能会遇到Java无法使用定义的内存的问题,因为它已经被OS,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天全站免登陆