Bagira
Bagira

Reputation: 2243

Maven: OutofMemoryError followed by Could not create the Java virtual machine

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?

Upvotes: 3

Views: 9496

Answers (4)

Andrey Borisov
Andrey Borisov

Reputation: 3170

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.

Upvotes: 6

davidfmatheson
davidfmatheson

Reputation: 3567

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"

Upvotes: 0

serg10
serg10

Reputation: 32677

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

Upvotes: 12

Peter Lawrey
Peter Lawrey

Reputation: 533530

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.

Upvotes: 2

Related Questions