Maven throws “java.lang.OutOfMemoryError”

2019-01-17 06:07发布

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 -Xmx256m but the output was java synopsis which indicated it's an invalid command.

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

Thanks,

9条回答
够拽才男人
2楼-- · 2019-01-17 06:49

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:

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"

查看更多
成全新的幸福
3楼-- · 2019-01-17 06:58

I always use this with my shell on ubuntu:

export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=500m"
查看更多
Animai°情兽
4楼-- · 2019-01-17 06:59

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

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

SET JAVA_HOME=C:\bea10\jrockit160_22
mvn install
查看更多
登录 后发表回答