How to install maven on windows
How to install maven on windows
Installing Maven on Windows
Last Updated: December 2, 2021
Learn to install Maven on a Windows operating system. In this maven installation guide, we are installing Maven on a Windows 11 machine. The steps are the same for a Windows 10 machine as well.
1. Windows Environmant Variables
Maven is a build and dependency management tool for Java applications development. Just like many other Java development tools, Maven is not installed as a Windows service, rather it is configured using the Windows environment variables.
2. Steps to Install and Configure Maven
Follow the steps needed to install maven on the windows operating system.
2.1. Verify Installed JDK and ‘JAVA_HOME’ Environment Variable
We must have Java installed on our computer and the JAVA_HOME must be set in the environment variables.
To install java, download JDK installer and install Java. Then add/update the JAVA_HOME variable to the JDK installation folder.
On my computer, JAVA_HOME is pointing to the JDK 17 installation folder.
2.2. Download and Extract Maven Zip File
We can download the latest version from Maven from the official website. Now we need to extract the downloaded zip file in any location.
Let us briefly discuss what these directories contain:
2.3. Add M2_HOME Environment Variable
Since Maven 3.5.0, the environment variable M2_HOME is not used/supported anymore. We can skip the M2_HOME variable setup with the latest version of Maven.
Now add the M2_HOME to windows environment variables. The value will be the installation location on your computer.
Note that it is an optional step, yet it is highly recommended. Many external IDEs and tools rely on M2_HOME variable to work with Maven.
2.4. Include ‘bin’ directory in PATH Variable
3. Verify Maven Installation
Maven installation is complete. Now, let’s test it from the windows command prompt.
The mvn command runs this batch file mvn.bat from bin folder of the Maven installation location. That’s why we added the the location to PATH environment variable.
This should show the Maven version information, path to Maven bin folder and installed Java version.
If you face any error in the command prompt then please cross-check all the above steps.
How to install maven on windows
Maven in 5 Minutes
Prerequisites
You must understand how to install software on your computer. If you do not know how to do this, please ask someone at your office, school, etc. or pay someone to explain this to you. The Maven mailing lists are not the best place to ask for this advice.
Installation
Maven is a Java tool, so you must have Java installed in order to proceed.
First, download Maven and follow the installation instructions. After that, type the following in a terminal or in a command prompt:
It should print out your installed version of Maven, for example:
Depending upon your network setup, you may require extra configuration. Check out the Guide to Configuring Maven if necessary.
If you are using Windows, you should look at Windows Prerequisites to ensure that you are prepared to use Maven on Windows.
Creating a Project
You need somewhere for your project to reside. Create a directory somewhere and start a shell in that directory. On your command line, execute the following Maven goal:
If you have just installed Maven, it may take a while on the first run. This is because Maven is downloading the most recent artifacts (plugin jars and other files) into your local repository. You may also need to execute the command a couple of times before it succeeds. This is because the remote server may time out before your downloads are complete. Don’t worry, there are ways to fix that.
You will notice that the generate goal created a directory with the same name given as the artifactId. Change into that directory.
Under this directory you will notice the following standard project structure.
The src/main/java directory contains the project source code, the src/test/java directory contains the test source, and the pom.xml file is the project’s Project Object Model, or POM.
The POM
The pom.xml file is the core of a project’s configuration in Maven. It is a single configuration file that contains the majority of information required to build a project in just the way you want. The POM is huge and can be daunting in its complexity, but it is not necessary to understand all of the intricacies just yet to use it effectively. This project’s POM is:
What did I just do?
You executed the Maven goal archetype:generate, and passed in various parameters to that goal. The prefix archetype is the plugin that provides the goal. If you are familiar with Ant, you may conceive of this as similar to a task. This archetype:generate goal created a simple project based upon a maven-archetype-quickstart archetype. Suffice it to say for now that a plugin is a collection of goals with a general common purpose. For example the jboss-maven-plugin, whose purpose is «deal with various jboss items».
Build the Project
The command line will print out various actions, and end with the following:
You may test the newly compiled and packaged JAR with the following command:
Which will print the quintessential:
Java 9 or later
By default your version of Maven might use an old version of the maven-compiler-plugin that is not compatible with Java 9 or later versions. To target Java 9 or later, you should at least use version 3.6.0 of the maven-compiler-plugin and set the maven.compiler.release property to the Java release you are targetting (e.g. 9, 10, 11, 12, etc.).
In the following example, we have configured our Maven project to use version 3.8.1 of maven-compiler-plugin and target Java 11:
Running Maven Tools
Maven Phases
Although hardly a comprehensive list, these are the most common default lifecycle phases executed.
There are two other Maven lifecycles of note beyond the default list above. They are
An interesting thing to note is that phases and goals may be executed in sequence.
This command will clean the project, copy dependencies, and package the project (executing all phases up to package, of course).
Generating the Site
Conclusion
We hope this quick overview has piqued your interest in the versatility of Maven. Note that this is a very truncated quick-start guide. Now you are ready for more comprehensive details concerning the actions you have just performed. Check out the Maven Getting Started Guide.
How to Install Maven on Windows 10
Azhwani • Jun 12, 2022 • maven • 5 mins read
Table of Contents [ Show ]
In this quick tutorial, we are going to highlight how to install Maven on Windows 10.
In short, Maven is a build automation and dependency management tool for Java based applications. To build a project, Maven uses its project object model (POM) and a set of plugins.
For this tutorial, I will be using:
Note: We have also written a nice article on how to install maven on mac. Feel free to check it.
Install JDK and Set up JAVA_HOME
The installation process of Apache Maven is quite simple, we just need to extract the Maven’s zip file and set up some environment variables.
However, Maven requires JDK to perform some important operations such as code compilation.
So, before installing Maven on Windows 10, we need to make sure that Java JDK is installed and the JAVA_HOME environment variable is properly configured on our machine.
Please refer to how to install on Windows 10 for more details.
Another important thing to keep in mind is that:
Apache Maven 3.3.1+ requires JDK 1.7 or above
Apache Maven 3.2.1->3.2.5 requires JDK 1.6
Apache Maven 2.2 to 3.1.1 requires JDK 1.5
Apache Maven 2.0 to 2.1 requires Java 1.4
We can type the following commands to check which JDK version is installed on our machine:
As we can see, the installed version of JDK is 1.8.0_261.
Download Apache Maven for Windows
We can download Maven directly from the official website: https://maven.apache.org/download.cgi. Make sure to download the latest stable release which is now 3.8.6.
Install Apache Maven on Windows 10
Now, let’s download apache-maven-3.8.6-bin.zip and unzip it to a specific folder of our choice, for example: C:\Users\Asus\soft\apache-maven-3.8.6
That’s all, NO installation is required to work with Mvn. Cool, right?
Now, let’s briefly explain what contains each directory:
bin contains all the batch and shell scripts that are necessary for Maven execution
boot contains all the tools required to start Maven
conf contains the basic configuration such as the default settings.xml file
lib, as the name implies, contains all the libraries and extensions used by Maven
Add MAVEN_HOME Environment Variable
The next step is to configure the MAVEN_HOME variable on Windows 10.
Since Maven 3.5.0, setting up MAVEN_HOME environment variable is optional. However, it is a good practice since many IDEs and tools use it to run Maven.
MAVEN_HOME should point to the folder where we extracted the Maven zip file, which is C:\Users\Asus\soft\apache-maven-3.8.6 in our case.
Follow these steps to add the MAVEN_HOME environment variable:
1- Type “edit” in the Window search box, then click on the “Edit the system environment variables”
2- Next, select the “Environment Variables…” button
3- Click on the “New…” button and put MAVEN_HOME as variable name and C:\Users\Asus\soft\apache-maven-3.8.6 as variable value
Another way to set up MAVEN_HOME is to use command lines. To do so, open a new command prompt as administrator and type the following command:
Add %MAVEN_HOME%\bin to the PATH
Now let’s add the last missing piece of the puzzle. This step is very important to run the Mvn command everywhere directly from the command prompt.
To do so conveniently, we need to edit the PATH variable by appending the Maven bin folder %MAVEN_HOME%\bin.
Once done, we can save the applied changes by clicking on the OK button.
Please bear in mind that we can accomplish the same thing using this command line:
Verify Mvn Installation
Now that we put all the pieces together, let’s test if Apache Maven is successfully installed on Windows 10.
To verify the installation, we run:
The mvn command is a direct shortcut to the mvn.bat batch file. This is the main idea behind adding the bin folder to the PATH environment variable.
As shown above, the command indeed displays the Maven version, Maven bin folder, Java version, and operating system information.
Common Issues
Here, we are going to put the focus on the common problems that we may face while installing Maven.
1) mvn is not recognized as an internal or external command
This means that the installation is not done properly, make sure %MAVEN_HOME%\bin is prepended to the PATH variable the right way.
2) JAVA_HOME environment variable is not defined correctly
This simply means that JDK is not installed and the JAVA_HOME variable is not properly configured.
3) Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
In this case, you need to download the binary zip archive file, instead of the source zip archive.
Conclusion
In this short article, we walked you through the steps of how to install Maven on Windows 10.
Please feel free to reach out to me if you encounter any issues.
Liked the Article? Share it on Social media!
If you enjoy reading my articles, buy me a coffee в•. I would be very grateful if you could consider my request вњЊпёЏ
How to Install Maven on Windows
Home » SysAdmin » How to Install Maven on Windows
Apache Maven is a build-automation tool designed to provide a comprehensive and easy-to-use way of developing Java applications. It uses a POM (Project Object Model) approach to create a standardized development environment for multiple teams.
In this tutorial, we will show you how to install Apache Maven on a system running Windows.
How to Install Maven on Windows
Follow the steps outlined below to install Apache Maven on Windows.
Step 1: Download Maven Zip File and Extract
1. Visit the Maven download page and download the version of Maven you want to install. The Files section contains the archives of the latest version. Access earlier versions using the archives link in the Previous Releases section.
2. Click on the appropriate link to download the binary zip archive of the latest version of Maven. As of the time of writing this tutorial, that is version 3.8.4.
3. Since there is no installation process, extract the Maven archive to a directory of your choice once the download is complete. For this tutorial, we are using C:\Program Files\Maven\apache-maven-3.8.4.
Step 2: Add MAVEN_HOME System Variable
1. Open the Start menu and search for environment variables.
2. Click the Edit the system environment variables result.
3. Under the Advanced tab in the System Properties window, click Environment Variables.
4. Click the New button under the System variables section to add a new system environment variable.
5. Enter MAVEN_HOME as the variable name and the path to the Maven directory as the variable value. Click OK to save the new system variable.
Step 3: Add MAVEN_HOME Directory in PATH Variable
1. Select the Path variable under the System variables section in the Environment Variables window. Click the Edit button to edit the variable.
2. Click the New button in the Edit environment variable window.
3. Enter %MAVEN_HOME%\bin in the new field. Click OK to save changes to the Path variable.
Note: Not adding the path to the Maven home directory to the Path variable causes the ‘mvn’ is not recognized as an internal or external command, operable program or batch file error when using the mvn command.
4. Click OK in the Environment Variables window to save the changes to the system variables.
Step 4: Verify Maven Installation
In the command prompt, use the following command to verify the installation by checking the current version of Maven:
After reading this tutorial, you should have a copy of Maven installed and ready to use on your Windows system.
How to install Maven on Windows 10
Maven is build tool primary for Java projects. In this tutorial I will describe how to install maven on Windows 10 operating system.
Download and install Java
To use maven we need to install Java first. If maven is used for Java projects java jdk should be installed, otherwise jre would be enough. Jdk or Jre could be found here.
Download maven
Add System variables
Right click on the Start button and select System :
In the System window click on Advanced system settings in the left menu. System properties pop-up will be opened. Click on Environment Variables :
Now we need to add the following variables to the System variables :
Add JAVA_HOME variable
JAVA_HOME points to the folder where java is installed and should have the value like this:
Add M2_HOME and MAVEN_HOME variables
M2_HOME and MAVEN_HOME variables should have the same value and point to the folder where maven was extracted:
Add Maven to PATH variable
Find the PATH variable in System variables and click on Edit button. The Edit environment variable pop-up will be opened. Press the New button and add the following value:
Verify installation
Open terminal (command prompt) and enter the following: