Skip to main content
Guides Menu

JAVA_HOME Explained

What is JAVA_HOME, why Maven and Gradle need it, and how to set it on Windows without mistakes. Covers JDK vs JRE, multi-version setups, and common errors.

Vishal Hulawale
April 2026·12 min read

JAVA_HOME is an environment variable that tells build tools and IDEs where your Java Development Kit is installed. Misconfiguring it is the single most common reason Maven and Gradle builds fail on Windows.

What Is JAVA_HOME?

JAVA_HOME is a Windows environment variable that stores the path to your Java Development Kit (JDK) installation directory. When a build tool like Apache Maven or Gradle starts up, one of the first things it does is read the JAVA_HOME variable to locate the JDK — specifically to find the Java compiler (javac.exe), the jar tool, and the libraries needed to compile your project.

A correctly set JAVA_HOME looks like this:

JAVA_HOME=C:\Program Files\Java\jdk-21.0.10

Common Mistake: Do NOT point JAVA_HOME to the bin subfolder. It should point to the root of the JDK directory.

Why Do Maven and Gradle Need It?

Maven needs more than just java.exe. It needs access to the JDK's entire directory structure to find the compiler, the archive tool, and required libraries. Without JAVA_HOME, Maven cannot reliably "walk" the file system to find these tools based just on a PATH entry.

JAVA_HOME vs. PATH

VariablePurpose
JAVA_HOMEPoints to the JDK root. Used by build tools.
PATHMakes commands like "java" runnable globally.

How to Set It (Quick Steps)

  1. Open System Properties (search for "Env" in Start).
  2. Click Environment Variables.
  3. Under System variables, click New.
  4. Set Name: JAVA_HOME.
  5. Set Value: Path to your JDK (e.g., C:\Program Files\Java\jdk-21).
  6. Edit the Path variable and add %JAVA_HOME%\bin.

Frequently Asked Questions

Q.Does JAVA_HOME point to the JDK root or the bin folder?

JAVA_HOME should point to the JDK root directory — e.g., C:\Program Files\Java\jdk-21.0.10. Do NOT include the \bin subfolder in JAVA_HOME. The bin folder belongs in your PATH entry instead (%JAVA_HOME%\bin).

Q.Do I need both JAVA_HOME and the bin directory in PATH?

Yes. JAVA_HOME is used by build tools (Maven, Gradle, Ant) to locate the JDK root. The PATH entry (%JAVA_HOME%\bin) lets you run "java", "javac", and "jar" commands directly from any terminal. Both are needed.

Q.What is the difference between a JDK and a JRE, and does JAVA_HOME care?

The JDK (Java Development Kit) includes the compiler (javac) and other development tools in addition to the runtime. The JRE (Java Runtime Environment) only includes what is needed to run Java applications. JAVA_HOME must point to a JDK — not a standalone JRE — because Maven, Gradle, and other build tools require the compiler.

Q.Can I have multiple Java versions installed and switch between them?

Yes. Install multiple JDK versions and update JAVA_HOME to point to the one you want active. You can also reorder PATH entries. Run "where java" to confirm which java.exe Windows resolves first. Some teams use wrapper scripts or version managers to automate the switch.

Q.Do I need JAVA_HOME for just running Java programs?

No. If you only want to run Java applications (not develop them), you just need java.exe in your PATH. JAVA_HOME is specifically used by build tools and IDEs that need to locate the full JDK directory structure.

Related Guides