Configuring the heap size

Once you have installed Maven in your system, the next step is to fine-tune it for optimal performance. By default, the maximum heap allocation is 256 - 512 MB (-Xms256m to -Xmx512m). This default limit does not work while building a large, complex Java project, and it is recommended that you have at least 1024 MB of maximum heap. If you encounter the java.lang.OutOfMemoryError error at any point during a Maven build, it is mostly due to the lack of memory. You can use the MAVEN_OPTS environment variable to set the maximum allowed heap size for Maven at a global level.

The following command will set the heap size in Linux. Make sure that the value set as the maximum heap size does not exceed your system memory of the machine ...

Get Mastering Apache Maven 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.