MAVEN_OPTS : How to increase JVM memory

In this post, we will see how to increase JVM memory using the environment variable MAVEN_OPTS.Sometimes, while running large number of JBehave stories we might get OutOfMemoryError at runtime.

For example, we might get something like this:

Caused by: java.lang.OutOfMemoryError: PermGen space

What is MAVEN_OPTS?

MAVEN_OPTS is an environment variable. It defines options for the JVM that executes Maven. We can set / increase JVM memory with this variable. We can set it according to our operating system

For example, on *nix system we can use

export MAVEN_OPTS=

On Windows, we can use

set MAVEN_OPTS=

If you are getting an OutOfMemoryException when running maven, we can try increasing the JVM memory to resolve this error.

MAVEN_OPTS=”-Xmx512M -XX:MaxPermSize=512m”

This will allocate 512MB of RAM to Maven.

On Windows Operating system:

We can set or increase the memory in many ways.

For example: using the windows command prompt

/> set MAVEN_OPTS=”-Xmx512M -XX:MaxPermSize=512m”

We may also set the  variable  in Environment variables in

Control Panel >> System >> Advanced >>  Environment Variables…

 

Environment_Variable_Windows

 

 

To enter new variable click on ‘New’ under user variables, then enter MAVEN_OPTS as variable name, and the value

“-Xmx512M -XX:MaxPermSize=512m”

If you already have set the environment variable , edit it to increase the memory. Also, note that the value 512M is chosen for example sake. The most suitable value depends and varies with the environment.

Related Posts