3

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?

Stu Thompson
  • 38,370
  • 19
  • 110
  • 156
Bagira
  • 2,149
  • 4
  • 26
  • 55

4 Answers4

12

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
serg10
  • 31,923
  • 16
  • 73
  • 94
6

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.

Bagira
  • 2,149
  • 4
  • 26
  • 55
Andrey Borisov
  • 3,160
  • 18
  • 18
2

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • 1
    And check also your memory use. If there is no free memory, this won´t help you anyway – Christian Lendel Jul 27 '12 at 12:09
  • @ChristianLendel I have checked the memory and have tried the same stuff after freeing a significant amount of memory but to no avail. – Bagira Jul 27 '12 at 12:30
  • @Peter Even if I am using 32 bit combination, I am trying to use only 2GB of memory which should be fine for 32 bit combination as well. Where do you see the problem in this. May be i am missing something. Keeping in mind I have sufficient free memory available – Bagira Jul 27 '12 at 12:32
  • On windows you can only allocate a heap of 1.2 to 1.5 GB depending on your OS version. This is a limitation of the OS. – Peter Lawrey Jul 27 '12 at 12:48
  • http://stackoverflow.com/questions/1434779/maximum-java-heap-size-of-a-32-bit-jvm-on-a-64-bit-os maybe this will help you a bit – Christian Lendel Jul 30 '12 at 14:25
0

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"
davidfmatheson
  • 3,539
  • 19
  • 27