Agentic AI with Java: Live Cohort
MavenInstalling Maven

Maven Installation on Windows

Install a JDK and Apache Maven on Windows, set JAVA_HOME and Path correctly, verify with mvn -v, and fix the errors beginners hit most often.

Maven is written in Java, so Java has to come first. The order on Windows is: install a JDK, tell Windows where it is, then download Maven and tell Windows where that is. Both "tell Windows" steps are about environment variables, and almost every installation problem comes from getting one of them slightly wrong.

How Windows finds mvn and java through the Path and JAVA_HOME environment variables

Step 1: install a JDK

Any JDK from version 17 upwards works for this course (17, 21, 25 and so on). If java -version already shows one of those, skip to Step 2.

Download the installer

Search for "Java 21 download" and open Oracle's download page, or use a free OpenJDK build such as Eclipse Temurin or Amazon Corretto. Choose the Windows x64 MSI Installer.

Run it

Double click the downloaded .msi and click Next until it finishes. By default it installs to a folder like:

C:\Program Files\Java\jdk-21

Set JAVA_HOME

Press the Windows key, search "Edit the system environment variables", open it and click Environment Variables. Under System variables click New:

FieldValue
Variable nameJAVA_HOME
Variable valueC:\Program Files\Java\jdk-21

JAVA_HOME points to the JDK folder itself, not to its bin folder. Maven reads this variable to find Java.

If you are not allowed to edit system variables on your machine, create the same variables under User variables. That works too.

Add the JDK bin folder to Path

Still in the same window, select the Path variable, click Edit, then New, and add:

C:\Program Files\Java\jdk-21\bin

You can also write %JAVA_HOME%\bin, which keeps working when you later upgrade Java and only change JAVA_HOME. Click OK on every dialog.

Verify

Open a new Command Prompt and run:

java -version

You should see something like java version "21.0.7". If you see it, Java is ready.

Step 2: download and install Maven

Download the binary ZIP

Go to maven.apache.org/download.cgi and download the Binary zip archive, named like apache-maven-3.10.0-bin.zip. Do not download the -src file, that is Maven's own source code.

Apache Maven download page with the binary zip archive link highlighted

The download page lists the binary archives first. The video picked 3.9.11, which was current at recording time.

Extract it

Extract the ZIP anywhere you like. Keeping it at the root of C: keeps paths short. Right click the ZIP, choose Extract All, and then open the extracted folder until you see the bin, boot, conf and lib folders.

Watch out for the nested folder: Extract All usually creates C:\apache-maven-3.10.0-bin\apache-maven-3.10.0\. The folder you want is the inner one that contains bin.

Add Maven's bin folder to Path

Open Environment Variables again, edit Path, click New and paste the full path up to bin:

C:\apache-maven-3.10.0-bin\apache-maven-3.10.0\bin

Optional: set MAVEN_HOME

Some tools and older guides look for MAVEN_HOME. It is optional, and Maven itself does not need it. If you want it, create a system variable MAVEN_HOME that points to the Maven folder without bin:

C:\apache-maven-3.10.0-bin\apache-maven-3.10.0

Verify

Open a new Command Prompt and run:

mvn -v

Expected output (your versions and paths will differ):

Apache Maven 3.10.0 (...)
Maven home: C:\apache-maven-3.10.0-bin\apache-maven-3.10.0
Java version: 21.0.7, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-21
Default locale: en_IN, platform encoding: UTF-8
OS name: "windows 11", version: "10.0", arch: "amd64", family: "windows"

Read this output carefully. It tells you which Maven is running, where it lives, and which Java it is using. When a build behaves strangely later, mvn -v is the first thing to check.

What each variable does

VariablePoints toNeeded?Used by
JAVA_HOMEJDK folder, for example C:\Program Files\Java\jdk-21Yes (strongly recommended)Maven, IDEs, many Java tools
Path entry for the JDK...\jdk-21\binYesSo java and javac work in any terminal
Path entry for Maven...\apache-maven-x.y.z\binYesSo mvn works in any terminal
MAVEN_HOMEMaven folder without binOptionalSome older tools and scripts

Common errors and fixes

PowerShell or Command Prompt?

Both work for mvn -v. When you start passing -D options (next section), PowerShell can split values that contain dots. Command Prompt is the simplest choice for this course. In PowerShell, wrap each -D... argument in double quotes.

Try It Yourself

  1. Install a JDK 17 or newer and confirm java -version and javac -version both work.
  2. Install Maven and confirm mvn -v shows the Maven home and the Java runtime you expect.
  3. Break it on purpose: temporarily rename JAVA_HOME to JAVA_HOME_X, open a new terminal and run mvn -v. Read the error, then fix it.
  4. Run echo %JAVA_HOME% and where mvn in Command Prompt to see exactly which folders Windows is using.

Official references


Written By: Shramik Masti

How is this guide?

Last updated on