4.12.14

Steps to install and configure Maven

Steps to install Maven

Prerequisite - Ensure that Java is installed, and the environment variable 'JAVA_HOME' is set as follows:
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_10

Download and unzip the maven binary file into a location like 'C:\Program Files\Apache\maven'. There is no exe to run.

Set the environment variables. Open the cmd prompt and type in the below commands as is

set M2_HOME=C:\Custom_Install_Dir\Apache\maven
set MAVEN_HOME=C:\Custom_Install_Dir\Apache\maven

Then append this to the Path variable as below, so that we can run the maven commands from anywhere
set Path=C:\Apache\maven\apache-maven-3.6.1\bin;

You can also do this by directly editing the Environment Variables, if you have admin rights.

How to check if maven has been installed correctly?

If we get an output like below to the command 'mvn -version', then we are all set

That's it, maven is installed and configured!



Some DONTs -
  • No need to set up MAVEN_OPTS Env param anymore.
    • All the options can now be set via the JVM Config file - to be added as - ${maven.projectBasedir}/.mvn/jvm.config 
    • This file will become part of your project and will be checked in along with your project.
    • Also this is way easier than having to get admin rights in enterprise setups.
  • Dont place your maven in a dir having spaces in its path.

Common Troubleshooting -
  •  If you are still having issues, even after following the above steps correctly, first restart the machine before doing any more troubleshooting
  • If 'mvn' command does not work directly, give the entire path till the bin dir of maven, and then try - if this works, then it means maven is installed and recognized, but it cannot run from everywhere. So all you need to fix are the Environment Variables.
  • By default Eclipse points to its own Embedded version of Maven and this could be different from the one that you installed, so we should update Eclipse to use the same Maven package and version via Eclipse > Preferences
  • Ensure that the Path variable has both these values - C:\Program Files\Java\jdk1.8.0_211\bin;C:\Apache\maven\apache-maven-3.6.1\bin;

No comments:

Post a Comment