3
votes

I am trying to use maven for my project work but i am stuck with memory related issues.

When i run the maven i get the heap space error which i fixed using the following line

set MAVEN_OPTS="-Xmx1586m"

after this when i run the maven again, i don't get the heap space error but rather i get the PermGen space error. For solving that i used the following syntax

set MAVEN_OPTS="-Xmx1586m -XX:MaxPermSize=512m"

but once i start using the MaxPermSize option i get the following error

Invalid maximum heap size: -Xmx1586m -XX:MaxPermSize=512m

Could not create the Java virtual machine.

I have tried setting different value combination for Xmx and MaxPermSize to bring the size in control but all are invalid.

I get this error only when i put MaxPermSize option in the MAVEN_OPTS. Once i remove that option i don't get the error mentioned above but i do get the PermGen error.

Any suggestions what I am doing wrong?

4

4 Answers

6
votes

you can try to set the initial heap size and initial permgen size relatively small, but set the proper max heap and pergent via -Xms128m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=256m

Also don't set permgen to 512 - it's too much for typical scenarious.

Also you may want to use fork option with maven and start plugin execution in different JVMs at all.

For example

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.5.1</version>
    <configuration>
      <fork>true</fork>
    </configuration>
  </plugin>

Also, while allocating memory also make sure that you have that much free memory available.

12
votes

The problem is that java has not understood your command line options. The message:

Invalid maximum heap size: -Xmx1586m -XX:MaxPermSize=512m

is telling you that java has used the entire String "-Xmx1586m -XX:MaxPermSize=512m" to try to set the maximum heap size.

My guess is that you need to set your environment variable without using quotes. Try:

set MAVEN_OPTS=-XMx1586m -XX:MaxPermSize=512m
2
votes

My guess is you have a 32-bit JVM on a 32-bit OS and you can't create an application that big. Try using less memory or using a 64-bit JVM on a 64-bit OS.

0
votes

Could it be just a capitalization issue? You have:

set MAVEN_OPTS="-XMx1586m -XX:MaxPermSize=512m"

when you should probably have (note the lower-case "m"):

set MAVEN_OPTS="-Xmx1586m -XX:MaxPermSize=512m"