Pages

Tuesday, February 20, 2018

How to fix out of memory error in Maven – “java.lang.OutOfMemoryError: PermGen”

How to fix out of memory error in Maven – “java.lang.OutOfMemoryError: PermGen”

While compiling/building a project in Maven, you might sometimes encounter the following error:

[shell]java.lang.OutOfMemoryError: PermGen[/shell]

It might be caused due to any of the following points:

  1. You are building a very big multi-module project, each module requires a certain amount of memory so with increasing number of modules the amount of required memory increases as well until the JVM finally runs out of “Java heap space”.
  2. You are using some plugins that perform memory-intensive operations like analyzing the class files of all project dependencies.
  3. You are using the Maven Compiler Plugin with the option fork=false (default) and your project has a lot of source files to compile. When using the Java compiler in embedded mode, each compiled class will consume heap memory and depending on the JDK being used this memory is not subject to gargabe collection, i.e. the memory allocated for the compiled classes will not be freed. The resultant error message typically says “PermGen space”.

Courtesy: OutOfMemoryError – Apache Maven

To solve this, we need to increase max memory for permanent heap space, using MAVEN_OPTS environment variable, as follows:

On Windows:

[shell]set MAVEN_OPTS=-Xmx512m -XX:MaxPermSize=512m[/shell]

On Linux:

[shell]export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=512m"[/shell]

For the special case of the Maven Compiler Plugin, you also have the option to configure the plugin to use fork=true.

No comments:

Post a Comment