This article was last updated on : November 4th, 2016 at 4:09 pm

Setup Maven in windows 7, eclipse and learn pom.xml

This article provides a step by step guide to setup Maven in windows 7. First we will download Maven from apache website and later we will configure it. The same approach is applicable in other windows versions.

Maven is a highly used Java based build tool. It is used to build Java projects. There are lot of other tools also present to build a project but Maven has one strong feature project object model (pom.xml). Project Object Model (POM) help us in project builds, dependency management, documentation creation, site publication, and distribution publication.

Install Maven in windows 7

Steps we will cover while installing Maven in windows 7

In this tutorial of maven installation we will cover these steps :

  1. We will check properly whether Java 1.5 or higher version is installed or not. In case proper version of JDK is not installed then we need to install Java from scratch. Maven will not work in your system without Java.
  2. We will download the latest Maven files from its official website.
  3. We will extract downloaded Maven files into a local directory.
  4. We will configure Maven as system variable.
  5. We will verify Maven installation using command prompt.
  6. We will see some extra steps – how can we change the default Maven installation directory?

Let us see the above mentioned steps one by one :

Step 1 : Make sure Java is installed in your windows operating system.

Make sure Java is installed in your system. To do so open your command prompt and type java -version.
In case Java is properly installed in your system. You will see similar output :
java -versionC:\Users>java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

If Java or JDK is not installed properly then you will receive an error message. In this case download the latest JDK installer and install it from scratch. Please install JDK using this tutorial : http://www.wikihow.com/Install-the-Java-Software-Development-Kit. Maven will not work if Java is not installed in your system. Maven is a Java based build tool.

Step 2 : Please download the maven from apache official website.

It is recommended to download the latest maven from apache official website.

Download link : Apache Maven latest binary .tar.gz/.zip.

You will find an image as given below.

Guide to setup Maven in windows

This image is showing the maven zip, jar and bin files

Please download its binary version (bin) either in .tar.gz or .zip format.

Step 3 : Extract and save Maven files.

Extract this Maven source files either in your D or C drive. Feel free to extract files in any directory. Once it is extracted we will copy the complete directory location of Maven file. This directory location is value for environment variables MAVEN_HOME and M2_REPO.

I have extracted the downloaded Maven files in D:\Program Files. So for me Maven installation directory is D:\Program Files\apache-maven-3.3.3.

Extracted file should look like below image :

Showing list of extracted Maven files.

Now we need to set Maven as an environment variable because Maven not run as a service like other applications and software (For example MySQL). We have some articles on MySQL.

In next steps we will configure Maven as an environment variable. We will verify Maven installation using Command Prompt.

Step 4 : Open “Control Panel\System and Security\System” in your windows system.

You will find an image as given below.

setting_up_MAVEN_HOME_as_environment_variable
Step 5 : Click on “Advanced system settings”.

It will ask “Do you want to allow the following program to make changes to this computer” then say “Yes”.
Now you will be navigated to another window as given below.

Setup Maven - Setting environment variable in system properties section
Step 6 : Click on environment variables tab.

 

Setup Maven - Environment variable setup
Step 7 : Now click on “New” tab.

 

Adding maven environment variable.

Enter these values in “New System Variable” window.

variable name – MAVEN_HOME

variable value - D:\Program Files\apache-maven-3.3.3

Add one more variable same way. The reason is some programs and applications consider M2_HOME for maven.

variable name – M2_HOME

variable value - D:\Program Files\apache-maven-3.3.3

Step 8 : Add MAVEN_HOME and M2_HOME to system path.

 

Setting path variable - Java maven installation
Step 9 : Check Maven installation using Command Prompt.

Now open command prompt as an administrator and type this command:

mvn -version

You will see an image given below.

Setup Maven - Testing Maven Installation

Change local maven installation directory

By default Maven save its dependencies to : ${user.home}/.m2/repository.

You may be interested to change the maven local repository location. It is not suggested unless you have specific requirement, less drive space or high interest to experiment it.

To change maven default repository location open “settings.xml” which will be in “conf” folder in maven installation directory.

If have extracted maven at D:\Program Files\apache-maven-3.3.3. So for me it is located at D:\Program Files\apache-maven-3.3.3\conf\settings.xml.\conf\settings.xml.
In settings.xml go to “<localRepository>” section.
Give the desired location you are willing. In case I am willing it to be at
D:\Program Files\apache-maven-3.3.3\.m2\repository
I will do it like
<localRepository>D:\Program Files\apache-maven-3.3.3\.m2\repository</localRepository>.
Like the same way you can change your repository.
Thanks for reading this article we will add more tips in this article.

More References : Apache Maven Project

Share this post:

Recent Posts

Leave a Comment