Take the 2-minute tour ×

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?


share|improve this question
Accepted this one. sigh!! –  Adeel Ansari Dec 17 '09 at 7:59
It's open question ;) The answer might be MAVEN_OPTS="-Xmx513m" etc. ;) –  cetnar Dec 17 '09 at 11:37
add comment

4 Answers

up vote 37 down vote accepted

Set the environment variable:

share|improve this answer
Sometimes is good also to extend perm memory size - MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m" –  cetnar Dec 18 '09 at 10:55
Setting MAVEN_OPTS alone is not sufficient if the build fails while running unit tests. In such cases, you may have to configure the "argLine" of maven-surefire-plugin explicitly. –  James Selvakumar Jan 13 at 2:29
add comment

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:

share|improve this answer
add comment

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

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

share|improve this answer
How can you get the current value of Xmx and MaxPermSize? After all, I can't increase the values without knowing what they're already set to. –  ArtOfWarfare Oct 11 '13 at 15:01
I'm not sure of MaxPermSize, but Xmx is usually 1/4th of the physical memory. Again, this may vary depending on the JRE implementations and/or "server", "client" mode of JVM. –  James Selvakumar Jan 13 at 2:33
add comment

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
share|improve this answer
add comment

Your Answer


