This article provides a step by step guide to setup Maven in windows 7. Firstly we will download Maven from apache website. Further we will configure it.
The same approach is applicable in other windows versions. For example windows 8 and 10.
There are lot of other tools also present to build a project. But Maven is a highly preferable Java based build tool. It builds Java projects for deployment.
Maven works well. It provides all the error like Java compiler. Developers can use the Maven error logs to solve their project compile and run time errors.
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 order to install maven please do these steps :
- Please check properly whether Java 1.5 or higher version is installed or not. If proper version of JDK is not installed then you need to install Java from scratch. Because Maven will not work in your system without Java.
- Once done with step 1, we will download the latest Maven files from its official website.
- Afterwards we will extract downloaded Maven files into a local directory.
- In this step we will configure Maven as system variable.
- We will verify Maven installation using command prompt.
- Finally in this step we will see some extra steps. How can we change the default Maven installation directory?
Now let us see the above mentioned steps one by one :
Step 1 : Make sure Java is installed in your windows operating system.
Please make sure Java is installed in your system. In order 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.
Please install Java otherwise Maven will not work. Because Maven needs Java to work.
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.
Please download its binary version (bin) either in .tar.gz or .zip format.
Step 3 : Extract and save Maven files in windows folder
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 :
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.
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.
Step 6 : Click on environment variables tab.
Step 7 : Now click on “New” tab.
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.
Step 9 : Check Maven installation using Command Prompt.
Now open command prompt as an administrator and type this command:
mvn -version
Once done you will see an image given below.
Change local maven installation directory
By default Maven save its dependencies to : ${user.home}/.m2/repository.
Moreover you can change the maven local repository location. But please do not change unless you have specific requirement. Change only if you have less drive space or high interest to experiment it.
In order to change maven default repository location open “settings.xml” which will be in “conf” folder in maven installation directory.
For me 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 atD:\Program Files\apache-maven-3.3.3\.m2\repository
So I will do it like this <localRepository>D:\Program Files\apache-maven-3.3.3\.m2\repository</localRepository>
.
Similarly you can change your repository.
Conclusion
Finally thanks for reading this article we will add more tips in this article.
So now you learnt how to install maven on windows.
You also learnt way to change the maven installation directory. So you can define a directory explicitly to save all the downloaded maven jars.
For more references please visit Apache Maven Project official website.
I often visit your blog and have noticed that you update it often. Nice article on setup maven in windows 7 and pom.xml.