Memory usage
It is possible that for some of the tasks Maven launches, such as the compilation of Java classes, or the generation of Javadoc, the default memory settings will not be enough.
If this happens, an OutOfMemoryError message will appear in the console. We can increase the maximum memory allocation of the JVM by defining the MAVEN_OPTS variable that allows us to pass parameters to the JVM that launches Maven. For example:
Linux:
export MAVEN_OPTS=-Xmx256M
Windows:
set MAVEN_OPTS=-Xmx256M
When there is not enough space for the loading of classes (PermGenSpace), this will produce an error like:
[INFO] Compilation failure Failure executing javac, but could not parse the error: The system is out of resources. Consult the following stack trace for details. java.lang.OutOfMemoryError: PermGen space at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
In this case, we will need to increase the PermGen space with the -XX:MaxPermSize parameter. For example:
Linux:
export MAVEN_OPTS=-Xmx256M -XX:MaxPermSize=64m
Windows:
set MAVEN_OPTS=-Xmx256M -XX:MaxPermSize=64m