tags:

views:

1152

answers:

4
+1  Q: 

Java heap space

I get this message during build of my project

java.lang.OutOfMemoryError: Java heap space

How do I increase heap space, I've got 8Gb or RAM its impossible that maven consumed that much, I found this http://vikashazrati.wordpress.com/2007/07/26/quicktip-how-to-increase-the-java-heap-memory-for-maven-2-on-linux/ how to do it on linux, but I'm on windows 7. How can I change java heap space under windows ?

+1  A: 

It should be the same command, except SET instead of EXPORT

  • set MAVEN_OPTS=-Xmx512m would give it 512Mb of heap
  • set MAVEN_OPTS=-Xmx2048m would give it 2Gb of heap
glowcoder
@glowcoder I agree that it should be the same command, but that doesn't make it true statement, here is why `C:\my_project>MAVEN_OPTS=-Xmx512m'MAVEN_OPTS' is not recognized as an internal or external command,operable program or batch file.`
Gandalf StormCrow
glowcoder is slightly wrong. You don't need to EXPORT the variables, but to assign a value to them you do need set.
JeremyP
You can also set MAVEN_OPTS as a windows environment variable if you want to use the same values for every build.
digitaljoel
@Gandalf you need to put the set in front of it @Jeremy yes, that's why it says to use set instead of export
glowcoder
A: 

You are looking for 2 options to java:

  • -Xmx maximum heap size
  • -Xms starting heap size

Put them in your command line invocation of the java executable, like this:

java -Xms512M -Xmx1024M my.package.MainClass

Keep in mind that you may want the starting and max heap sizes to be the same, depending on the application, as it avoids resizing the heap during runtime (which can take up time in applications that need to be responsive). Resizing the heap can entail moving a lot of objects around and redoing bookkeeping.

For every-day projects, make them whatever you think is good enough. Profile for help.

Phil
A: 

Edit your %M2_HOME%\bin\mvn.bat file. Add the line below:

set MAVEN_OPTS=-DXms_1024M -DXmx=1024M
crowne
+2  A: 

The environment variable to set is MAVEN_OPTS, for example MAVEN_OPTS=-Xmx1024m. The maxmem configuration in the pom only applies when you set the compiler plugin to fork javac into a new JVM. Otherwise the plugin runs inside the same VM as Maven and thus within the memory passed on the command line via the MAVEN_OPTS.

To set MAVEN_OPTS under Windows 7:

  1. Right click on My Computer and select Properties
  2. Click the Advanced System Settings link located in the left navigation of System Properties to display the Advanced System Properties
  3. Go to the Advanced tab and click the Environment Variables button located at the bottom of the Advanced System Properties configuration window
  4. Create a New user variable, set the Variable name to MAVEN_OPTS and set the Variable value to -Xmx1024m (or more)

Open a new command window and run mvn.

Pascal Thivent