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 of the Windows operating system. Installing Maven is very easy, just download the Apache Maven ZIP file from the Apache Maven Project website (https://maven.apache.org/download.cgi). You can download the apache-maven-3.3.9-bin.zip for using Maven on 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 variables like M2, M2_HOME into your Windows machine.
1.JDK
Now, you only need to extract the binary distribution and add the bin folder in PATH or add a couple of environment variables like M2, M2_HOME into your Windows machine.
What you need to Install Maven in Windows
Here are things you will need to install Maven on Windows:
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. JAVA_HOME
2. JAVA_HOME
Make sure that the 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 the JAVA_HOME environment variable.
Once you ensure that the above is in place, you need to follow the below steps to install Maven on your Windows machine.
1) Setup the following environment variables
I am using Cygwin that's why I am using the export command if you are using the DOS command prompt then you should use the "set" command version shown below.
Though simply adding the bin directory of the 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.
Once you ensure that the above is in place, you need to follow the below steps to install Maven on your Windows machine.
1) Setup the 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 the 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 the 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 the 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.
Once you have to add the bin directory of the 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 set up correctly you will see similar output as shown below:
At this point in time installation of Apache Maven is completed successfully and you are now ready to create and build a 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 the M2Eclipse plugin.
You can see that it prints the Apache Maven version, along with Maven home, Java version, Java home, and OS name.$ 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"
At this point in time installation of Apache Maven is completed successfully and you are now ready to create and build a 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 the M2Eclipse plugin.
Other Maven articles you may like
- What is the difference between Maven, ANT, and Jenkins? (answer)
- How to increase the heap size of Maven? (steps)
- Top 5 Courses to Learn Apache Maven in-depth (courses)
- How to fix Maven Eclipse Dependency search not working issue? (solution)
- How to install Maven in Windows 10? (steps)
- How to build a Java project using ANT? (article)
- How to create or modify build.xm in ANT? (tutorial)
- Top 5 Apache Maven Books for Free (books)
- 10 Points about Maven Java Developer should know (maven)
- 10 Maven Plugins Every Java Developers should know (plugins)
- 6 Free Maven and Jenkins Books for Java developers (books)
- How to fix invalid target release error in Maven (Solution)
- How to set a specific Java version for Maven (tutorial)
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.
ReplyDeleteMaven sounds so old and one idea better than Ant plus Ivy. What is the reason people still using it?
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.
ReplyDelete