Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install Apache Maven on Windows

Install Java, extract Maven and set the environment variables.

Windows Hosting2 min read10 steps7 screenshots

Requirements

  1. Maven runs on Java. Install a JDK and check it:
java --version
The Java version
  1. You need administrator rights to change the system environment variables.

Step 1: Download Maven

Open the Apache Maven download page and download the Binary zip archive (apache-maven-x.y.z-bin.zip).

The Maven download page

Step 2: Extract it

Extract the zip file to a folder such as C:\Program Files\Apache\maven. Inside you will find a folder like apache-maven-3.9.6.

Extracting Maven

Step 3: Set the environment variables

  1. Search for environment variables in the Start menu and open Edit the system environment variables. Click Environment Variables.
    Opening the environment variables
  2. Under System variables, click New. Name: MAVEN_HOME (or M2_HOME). Value: the Maven folder, for example C:\Program Files\Apache\maven\apache-maven-3.9.6.
    Creating the system variable
  3. Check that JAVA_HOME is set to your JDK folder. If not, add it too.
  4. Select Path, click Edit, click New and add %MAVEN_HOME%\bin.
    Adding Maven to the Path
  5. Click OK in all windows.

Step 4: Check Maven

Open a new Command Prompt:

mvn -v
The Maven version

You see the Maven version, the Java version and your operating system.

Troubleshooting

  1. If mvn -v is not found, check that %MAVEN_HOME%\bin is in the Path, and open a new window.
  2. Make sure Java is installed and JAVA_HOME is right.
  3. Use an administrator account to change system variables.

Why use Maven

  • Project management. A standard folder layout for projects.
  • Dependency management. Maven downloads the libraries your project needs. You do not have to copy JAR files.
  • Build automation. Define build steps (compile, test, package) once.
  • Reproducibility. Builds are the same on every computer.

Next steps

Create a project:

mvn archetype:generate -DgroupId=com.example -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
cd my-app
mvn package

Quick recap

  • Install a JDK, extract Maven, set MAVEN_HOME and the Path.
  • Check with mvn -v.
  • Use mvn package to build a project.