Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Maven Essentials

You're reading from   Maven Essentials Get started with the essentials of Apache Maven and get your build automation system up and running quickly

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher
ISBN-13 9781783986767
Length 184 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Russell E Gold Russell E Gold
Author Profile Icon Russell E Gold
Russell E Gold
Prabath Siriwardena Prabath Siriwardena
Author Profile Icon Prabath Siriwardena
Prabath Siriwardena
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. Apache Maven Quick Start FREE CHAPTER 2. Understanding the Project Object Model (POM) 3. Maven Archetypes 4. Maven Plugins 5. Build Lifecycles 6. Maven Assemblies 7. Best Practices Index

Configuring the heap size

Once you have Maven installed in your system, the very next step is to fine-tune it for an optimal performance. By default, the maximum heap allocation is 512 MB, which starts from 256 MB (-Xms256m to -Xmx512m). This default limit is not good enough to build a large, complex Java project, and it is recommended that you have at least 1024 MB of the maximum heap.

If you encounter java.lang.OutOfMemoryError at any point during a Maven build, then it is mostly due to a 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 any Unix-based operating system, including Linux and Mac OS X. Make sure that the value set as the maximum heap size does not exceed your system memory of the machine, which runs Maven:

$ export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=128m"

If you are on Microsoft Windows, use the following command:

$ set MAVEN_OPTS=-Xmx1024m -XX:MaxPermSize=128m

Here, -Xmx takes the maximum heap size and -XX:MaxPermSize takes the maximum Permanent Generation (PermGen) size.

Note

Maven runs as a Java process on JVM. As it proceeds with a build, it keeps on creating Java objects. These objects are stored in the memory allocated to Maven. This area of memory where Java objects are stored is known as heap. Heap is created at the JVM start and it increases as more and more objects are created up to the defined maximum limit. The -Xms JVM flag is used to instruct JVM about the minimum value that it should set at the time of creating the heap. The -Xmx JVM flag sets the maximum heap size.

PermGen is an area of memory managed by JVM, which stores the internal representations of Java classes. The maximum size of PermGen can be set by the -XX:MaxPermSize JVM flag.

When the Java virtual machine cannot allocate enough memory to Maven, it could result in an OutOfMemoryError. To know more about the Maven OutOfMemoryError, refer to https://cwiki.apache.org/confluence/display/MAVEN/OutOfMemoryError.

You have been reading a chapter from
Maven Essentials
Published in: Dec 2015
Publisher:
ISBN-13: 9781783986767
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime