Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - Could not reserve enough space for object heap error

Tags:

jvm

maven

I am Maven to build my Java project. After several successful build, I am now getting the following error:

Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

In my maven.sh file that my build is using, I have added the following as the first line

export MAVEN_OPTS=-Xmx512m

I am still getting the error.

Can anyone suggest a fix?

like image 496
TheCoder Avatar asked Aug 08 '12 08:08

TheCoder


2 Answers

I had the same issue and I figured Maven was not using the right jvm. You can check this with

mvn -version

In my case, the jvm specified in my JAVA_HOME and PATH was incorrect: I was using an x86 jdk 6 instead of an x64 jdk 7. Fixing this solved the issue.

like image 129
Didier L Avatar answered Oct 25 '22 13:10

Didier L


I ran into this same issue when I was trying to build the Cloudera Navigator SDK examples. I am using a 32-bit JVM and the compile seemed to go OK but the test afterwards failed with this error:

Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap

I tried setting MAVEN_OPTS=-Xmx512m but this had no effect- it failed with the same message. Even the value of 2097152KB in the error message was still the same (strange!).

I finally figured out that the heap size value had been hard-coded for the test in the pom.xml file! It had

<argLine>-Xmx2048m ...
</argline>

I edited pom.xml and changed that to -Xmx1024m and then maven was able to build and test everything with no problems.

So the lesson from this is that if you are building something given to you by someone else (such as Cloudera) and you get an error like this, check pom.xml carefully to see if the setting is hard-coded in there.

FYI- I think that using a 64-bit JVM might have also possibly resolved this, but I can't switch to 64-bit. We have some other stuff that we need to get this to work with that says that it only works with a 32-bit JVM (I can't really explain in any more detail than that here).

like image 29
Frank K. Avatar answered Oct 25 '22 13:10

Frank K.