11

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?

4
  • at what stage in the maven build is this failing? Is it during the tests run for example? could you provide more of the maven output? Commented Aug 8, 2012 at 8:56
  • [INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ my-configuration --- [INFO] No tests to run. [INFO] Surefire report directory: C:\target\surefire-reports Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine. Commented Aug 8, 2012 at 9:04
  • It fails regardless if I run my tests or not. It fails very early in the build. I am using a Windows machine and the Linux emulator Cygwin to run my maven build. The build also fails when I try it in Windows. It previously worked in Cygwin but not now. Commented Aug 8, 2012 at 9:30
  • certainly seems strange. Take a look at the following blog: myadventuresincoding.wordpress.com/2009/06/15/… also try the various suggestions in the comments as well. Maybe one of those will help you? Commented Aug 8, 2012 at 10:15

10 Answers 10

16

The solution was to set the forkMode of maven-surefire-plugin to 'never'. It seems that when tests are run, maven sure fire spawns a new JVM. Setting it to never fixed the issue.

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.7.2</version> <configuration> **<forkMode>never</forkMode>** <argLine>-Xms1024m -Xmx1024m -XX:MaxPermSize=2048m</argLine> <systemPropertyVariables> <user.name>${user.name}</user.name> </systemPropertyVariables> </configuration> </plugin> 
Sign up to request clarification or add additional context in comments.

Comments

12

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.

Comments

3

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).

Comments

2

I think you want to reserve more space than you have, with your settings: MAVEN_OPTS=-Xmx512m

Try to set it lower, since Maven starts only if it can reserve the whole space. This problem occurred to me and I could solve it like described.

Comments

2

Try to set variable: MAVEN_OPTS = -Xmx512m -XX:MaxPermSize=128m

Comments

2

Changing to MAVEN_OPTS = -Xmx512m helped me on a Windows 64 bit.

Comments

1

Try Java 64 bits and configure your java_home to this Java 64. obs.: javac -version and mvn -version needs return this Java 64.

Comments

0

As Didier L above said

This was exactly what problem I was having, we were running the x86 JVM instead of the 64 bit...

It fixed my issue when I changed to the 64bit JVM.

Comments

0

In IDEA IntelliJ IDE there is a setting on Maven -> Runner to use a specific JVM. The default for me was to use the JRE and not the JDK set on JAVA_HOME. Make sure to check that setting. Once i switched to use JAVA_HOME everything ran fine.

Comments

0

I tried this and its works for me-

maven version -3.2.5 java version -jdk1.7.0_10

-Xmx600m -XX:PermSize=256m

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.