Many times we get java.lang.OutOfMemoryError: java heap space while building our project either by using maven or ANT just because heap size is not enough to build the project. At this point we just want to increase the heap size used by ANT or MAVEN and this java tip will let you do this:
How to increase Java Heap size for Maven on Linux/Unix
How to increase Java Heap size for Maven on Linux/Unix
1. Open your mvn.sh file and add the following line:
export MAVEN_OPTS=-Xmx512m
this will allow to specify java heap space based on your project needs.
export MAVEN_OPTS=-Xmx512m
this will allow to specify java heap space based on your project needs.
How to increase Java Heap space for Maven on Windows
1. go to C:\apache-maven-2.2.1\bin
2. open your mvn.bat file and add the following line :
set MAVEN_OPTS=-Xmx512m
next time you run maven commands like mvn clean or mvn install it will use this heap size.
next time you run maven commands like mvn clean or mvn install it will use this heap size.
This article is in continuation of my earlier post on java heap 10 points on java heap space if you haven’ read that you may find some useful info there.
How to increase Java Heap size/space/memory for ANT on Linux/Unix
Similar to Maven you can specify ANT_OPTS to specify JVM specific arguments for ANT build tool. Here is step by step guide to change the java heap space for ANT:
Similar to Maven you can specify ANT_OPTS to specify JVM specific arguments for ANT build tool. Here is step by step guide to change the java heap space for ANT:
1. Go to ANT_HOME directry (directory where Ant has been installed)
2. Open ant.bat file and add following line on it
export ANT_OPTS=-Xmx512m
some time you may need to put the value –Xmx512M inside double quotes.
export ANT_OPTS=-Xmx512m
some time you may need to put the value –Xmx512M inside double quotes.
3. Done next time you run “ant” it will use modified java heap size and will not throw OutOfMemoryError till the new limit reached.
How to increase Java Heap size/space/memory for ANT on Windows
As shown above for Linux ANT_OPTS can also be used specify JVM specific arguments for ANT in windows. Here is step by step guide to increase the java heap memory for ANT in Windows:
As shown above for Linux ANT_OPTS can also be used specify JVM specific arguments for ANT in windows. Here is step by step guide to increase the java heap memory for ANT in Windows:
4. Go to ANT_HOME directry (directory where Ant has been installed)
5. Open ant.bat file and add following line on it
set ANT_OPTS=-Xmx512m
some time you may need to put the value –Xmx512M inside double quotes.
6. Done next time you run “ant” it will use modified java heap size and will not throw OutOfMemoryError till the new limit reached.
5. Open ant.bat file and add following line on it
set ANT_OPTS=-Xmx512m
some time you may need to put the value –Xmx512M inside double quotes.
6. Done next time you run “ant” it will use modified java heap size and will not throw OutOfMemoryError till the new limit reached.
4 comments:
This is exactly I was looking for setting heap size for ANT and Maven. just one question do we need to specify ANT_OPTS or MAVEN_OPTS in there respective batch file or we can just export heap size as environment variable ?
Definitely, you can set/export an environment variable without editing of the batch file. Moreover, it is a preferred method.
Definitely al0, but that could override any parameter which is getting set inside JAVA_OPTS in script but in normal case until you don't have complex build setup its better to use environment variable rather than changing batch file.
thanks for this post. its help me a lot. :)
Post a Comment