Picture of Brian Love wearing black against a dark wall in Portland, OR.

Brian Love

Increase Java Heap for Maven Build

If you have ever run into an issue with the Java Heap space when doing a Maven build, you can easily give more memory to Java. The error message from Maven will look like:

UNEXPECTED TOP-LEVEL ERROR:
 java.lang.OutOfMemoryError: Java heap space

The fix

I am on a mac, so it’s as simple as modifying the ~/.bash_profile file, adding the following two lines:

export MAVEN_OPTS="-Xmx2048m"
export _JAVA_OPTIONS="-Xms1024m -Xmx1024m -XX:MaxPermSize=512m"