Maven throws "java.lang.OutOfMemoryError"
Solution 1
Set the environment variable:
MAVEN_OPTS="-Xmx512m"
Solution 2
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:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx1024m</argLine>
</configuration>
</plugin>
Solution 3
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
Solution 4
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"
Solution 5
on a Unix-like system:
export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=512m"
user124858
Updated on April 27, 2020Comments
-
user124858 about 4 years
I'm compiling an open source project with "mvn install" but ended up with
java.lang.OutOfMemoryError: Java heap space
. I tried to executejava -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,
-
Arturs Mednis over 14 yearsSometimes is good also to extend perm memory size - MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m"
-
ArtOfWarfare over 10 yearsHow can you get the current value of
Xmx
andMaxPermSize
? After all, I can't increase the values without knowing what they're already set to. -
James Selvakumar over 10 yearsSetting 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 over 10 yearsI'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.
-
Surekha over 9 yearsI was getting this error on mvn install, using "mvn install -DMAVEN_OPTS=-Xmx1024m" solved my problem!
-
user2568374 over 7 years-bash: export: `-XX:MaxPermSize=256m': not a valid identifier
-
TomJava over 2 yearsCan I add Xmx1024m -Xms1024m as well?
-
Andriy Plokhotnyuk over 2 yearsYep, <argLine>-Xmx1g -Xms1g</argLine> should work