I have two version of environment variables for maven home - M2_HOME
and MAVEN_HOME
.
Which one needs to be set?
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 .
Set M2_HOME & PATH Create an environment variable named M2_HOME which refers to directory where maven was untarred/ unzipped. and then add this variable to PATH environment variable. $>export PATH=$M2_HOME/bin:$PATH. Click OK, then Edit the 'Path' user variable to add M2_HOME\bin folder in it.
Maven home: C:\Program Files\Apache Software Foundation\apache-maven-3.8.4. Java version: 11.0.11, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk11.0.11\ Default locale: en_IN, platform encoding: Cp1252.
2.2) Setting Maven Environment Variables - M2_HOME and Path We have to add the Maven bin directory to the Path variable. Open . bash_profile in your favorite text editor and add below lines to the end of it. You can relaunch Terminal to load these profile settings or use source .
MAVEN_HOME
is for Maven 1, M2_HOME
is for Maven 2 and later.
Maven 2 was a complete rewrite from Maven 1 and was not backwards compatible. Having the two different _HOME
variables means it is possible to run both on the same machine.
UPDATE
As of maven 3.5.0 neither of these environment variables should be specified. Instead, the path should be updated to include the mvn executable.
And, ironically, you must still use M2_HOME and M2 for Maven version 3. Otherwise, it fails, because they didn't follow this logical approach with Maven V3.x for some bizarre reason.
Consequently, it is not easy to support Maven 2 & Maven 3 on the same machine without rewriting your configuration.
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