Click here to download the latest version of MAVEN(Current version is 3.0.4).
Note*: Select binary file from list of options to download.
Once downloaded, Extract the zip file @ location where you want to install maven. After extraction folder structure would look like below.
Setting Environment Variable
Next step would be to set up environment variables related to Maven. Open Environment variable dialog box and add below env. variable.
Env. Variable 1:
Variable Name : “M2_HOME”
Variable Value : C:\Maven\apache-maven-3.0.4 (Assuming you have extracted the maven folder @ C:\Maven)
Env. Variable 2:
Variable Name : “M2”
Variable Value : %M2_HOME%\bin
Note*: Maven requires JDK to be installed properly. Check if JAVA_HOME environment variable is properly set or not.
Check Maven Installation
After setting all parameters, its time to check if Maven is installed properly or not.
To check installation of Maven open command prompt and type below command.
Output of the above command should be something like below.
If output is “’mvn’ is not recognized as an internal or external command, operable program or batch file.”
Then there should be some problem while setting the path of maven folder. You can check with path environment variable. Check if all path is set properly or not
Maven Repository Introduction
To resolve the dependency of a project Maven requires multiple JARs (Framework specific Jars or Project Jars). Maven will look for these Jars in certain locations these locations are called Repository (Maven Specific Terminology).
Maven has 3 different type of repository.
- Local Repository
- Central Repository
- Remote Repository
Local Repository Introduction
Maven local repository is a folder on local system which is used to store project’s dependencies (Jars). Whenever you try to build a project Maven will try to download all the required Jars in Local Repository (If it is not already present in Local Repository). Maven tries to avoid connecting remote system for multiple build of the same application by using Local Repository.
Creation of Local Repository
Local Repository will get created whenever you run any maven command for the first time.
Default Location of Local Repository
Maven default local repository will be created in user home directory with name “.m2”.
In windows it should be: echo %USERPROFILE%\.m2
In Unix or Linux it should be: echo $HOME\.m2
Custom Local Repository Location
To change the location of Default Local Repository you need to change the maven’s “settings.xml”, which will be located @ %M2_HOME%\conf.
In settings.xml try to find below lines.
localRepository | The path to the local repository maven will use to store artifacts. | | Default: ~/.m2/repository /path/to/local/repo -->
Local Repository path part is commented, provide the path of your custom directory and save it.