Tip : Setting heap size for maven applications

Some times we may need to provide good amount of heap space to maven to run the build. This may be because you are loading lot of resources like loading temporary db to run the test cases. Or one may like to run the web application using some embedded container like jetty. Here you can find how to set memory options with maven.

If you are facing PermGenSpace problem you should use “-XX:MaxPermSize=1024m” java option. Please note that value depends on needs of your application.

If you are facing OutOfMemory problem you should use “-Xmx1024M” . Again the value depends on your application needs.

How to set these on windows ?
You can create them as system properties with name MAVEN_OPTS and value “-Xmx1024M -XX:MaxPermSize=1024m“.

On Unix based systems like ubuntu :
You can add following two lines to your .profile file in home folder. Change the values according to your need.

MAVEN_OPTS='-Xmx1024M -XX:MaxPermSize=1024m'

You should use single quotes only here. If you use double or no quotes, it will complain. Hope this is useful for you. If there is a better way, please let the world know about 🙂 .


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s