How to install Maven on Windows 7,8 or 10?

There is no difference in installing Maven on Windows7, Windows 8, Windows 8.1 or Windows 10, you can follow the same steps to install Maven in any version Windows operating system. Installing Maven is very easy, just download the Apache Maven ZIP file from Apache Maven Project website (https://maven.apache.org/download.cgi). You can download the apache-maven-3.3.9-bin.zip for using Maven in your 64-bit Windows machine. Remember, Maven 3.3 requires JDK 1.7 or above to run, so make sure you already installed JDK 7 or JDK8. Once you download the binary distribution of Maven, half of the job is down. Now, you only need to extract the binary distribution and add the bin folder in PATH or add a couple of environment variable e.g. M2, M2_HOME into your Windows machine.



What you need to Install Maven in Windows

1) Make sure JDK is already installed. You need JDK 1.7 or above to run Maven 3.3. If you don't know how to install Java, see this guide for step by step tutorial.

2) Make sure that JAVA_HOME environment variable is defined and should point to the installation directory of Java. Maven uses this environment variable to find the Java installation directory. See here to learn more about JAVA_HOME environment variable.

Once you ensure that above is in place, you need to follow below steps to install Maven on your Windows machine:


1) Setup following environment variables
export M2_HOME=/Users/xxx/sdk/apache-maven-3.2.3
export M2=$M2_HOME/bin
export MAVEN_OPTS="-Xmx1048m -Xms256m -XX:MaxPermSize=312M"
export PATH=$M2:$PATH

I am using Cygwin that's why I am using the export command if you are using DOS command prompt then you should use the "set" command version shown below.

set M2_HOME=C:\\software\apache-maven-3.2.3
set M2=%M2_HOME%\bin
set MAVEN_OPTS="-Xmx1048m -Xms256m -XX:MaxPermSize=312M"
set PATH=%M2%;%PATH%

Though simply adding the bin directory of Maven installation folder to PATH is enough to run the "mvn" command, it's better to define well-known maven environment variables like M2_HOME and MAVEN_OPTS.

The M2_HOME is equivalent to JAVA_HOME and should point to the installation directory of Maven. On the other hand, MAVEN_OPTS is used by Maven script to fetch additional JVM arguments provided by the user. You can use this environment variable to increase the heap size of Maven by supplying JVM memory arguments e.g. -Xms and -Xmx. 

You can also read Maven Essentials to learn more about how Maven uses these environment variables.
How to install Maven on Windows 7 and 10

One you have to add bin directory of Maven folder, either directly or indirectly via an M2 environment variable, you should be able to run the mvn command from Cygwin or DOS command prompt. If Maven is setup correctly you will see similar output as shown below:

$ mvn -version
Apache Maven 3.2.3 
Maven home: C:\apache-maven-3.2.3
Java version: 1.6.0_37, vendor: Sun Microsystems Inc.
Java home: C:\Java\jdk1.6.0_37\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
You can see that it prints the Apache Maven version, along with Maven home, Java version, Java home and OS name.


At this point of time installation of Apache Maven is completed successfully and you are now ready to create and build Maven based Java project using different arch types. You can also use this locally installed Maven in eclipse instead of the default one installed by M2Eclipse plugin.



2 comments :

Chris FAKAR said...

Why to bother installing Maven, when we can use newer technology - Gradle? IMO it's better and offer better tools and utilities for building applications.

Maven sounds so old and one idea better than Ant plus Ivy. What is the reason people still using it?

Javin Paul said...

Hello @Chris, I agree that Gradle is out there but many projects still uses Maven. It's more Maven than Gradle in professional world. If you don't know Maven, then you will struggle to work with team.

Post a Comment