For example:-
MAVEN_OPTS=" -Xms512m -Xmx1024m -XX:MaxPermSize=1024m"
export MAVEN_OPTS
What does "-Xms512m -Xmx1024m -XX:MaxPermSize=1024m"
mean?
MAVEN_OPTS environment variable: This variable contains parameters used to start up the JVM running Maven and can be used to supply additional options to it. E.g. JVM memory settings could be defined with the value -Xms256m -Xmx512m .
You can start Maven with extra memory using MAVEN_OPTS environment variable.
M2_HOME is used by Maven, and again it tells the program where to find Maven installation. PATH is not suitable for that purpose, because it may contain many directories not related to Java or Maven.
To refer to environment variables from the pom. xml, we can use the ${env. VARIABLE_NAME} syntax. We should remember to pass the Java version information via environment variables.
After going through above comments, I clarify my doubts about MAVEN_OPTS and maven semantics. The MAVEN_OPTS environment variable contains parameters used to start up the JVM running Maven and can be used to supply additional options. This includes JVM memory pool parameters. Kindly refer this link and go through the document.
-Xmsn
Specifies the initial size, in bytes, of the memory allocation pool. This value
must be a multiple of 1024 greater than 1 MB. Append the letter k or K to indicate kilobytes,
or m or M to indicate megabytes. The default value is chosen at runtime based on system configuration. See Garbage Collector Ergonomics at
[http://docs.oracle.com/javase/7/docs/technotes/guides/vm/gc-ergonomics.html][2]
Examples:
-Xms6291456
-Xms6144k
-Xms6m
-Xmxn
Specifies the maximum size, in bytes, of the memory allocation pool. This value
must a multiple of 1024 greater than 2 MB. Append the letter k or K to indicate kilobytes, or m
or M to indicate megabytes. The default value is chosen at runtime based on system
configuration.
For server deployments, -Xms and -Xmx are often set to the same value. See Garbage
Collector Ergonomics at
[http://docs.oracle.com/javase/7/docs/technotes/guides/vm/gc-ergonomics.html][3]
Examples:
-Xmx83886080
-Xmx81920k
-Xmx80m
Documentation is great but it is not always complete. There are some additional things which you can do to figure things out yourself. In this case you know that MAVEN_OPTS is an environmental variable, which likely means it is used in shell script. So open up for example mvn.bat and search for MAVEN_OPTS to see how it is used.
You will find it is simply a way to specify Java command line arguments which will be in effect for the execution of Maven itself. As an example in the past I needed to increase the default permgen size to prevent issues during execution of a complex build.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With