> ## Content Index
> Fetch the complete content index at: https://www.ggorantala.dev/llms.txt
> Use this file to discover other available public pages before exploring further.

# No Compiler Is Provided in This Environment: Maven on a JRE
- URL: https://www.ggorantala.dev/no-compiler-provided-jre-rather-than-jdk/
- Published: 2026-12-01T06:53:01.000Z
- Updated: 2026-12-01T06:53:01.000Z
- Description: Maven's 'No compiler is provided in this environment' means the JVM running Maven has no Java compiler inside it, even if javac works in your terminal. How to see which Java Maven really picked, and the fix for the terminal, Eclipse, IntelliJ and CI.
- Author: Gopi Gorantala
- Tags: no-compiler-provided, maven-compiler-plugin, jdk-vs-jre, java-home, maven, jdk-setup, java-errors

## The build log, and the terminal that disagrees

The weird part comes first. You type `javac -version` in the same terminal and it answers. You type `java -version` and get 21\. Then `mvn clean install` on the fraud-rules module dies like this:

```log
[INFO] --- compiler:3.13.0:compile (default-compile) @ fraud-rules ---
[INFO] Compiling 14 source files with javac [debug target 21] to target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] BUILD FAILURE
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project fraud-rules: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

```

That's the shape Maven 3.9 prints with any 3.x compiler plugin. The plugin version and project name will differ on your screen; the message line won't. I'll be upfront that my sandbox couldn't reach Maven Central this run, so the block above isn't from my own Maven run. The message string itself I checked against the source that throws it, and everything else in this post comes from commands I did run.

"No compiler is provided in this environment" doesn't mean your machine lacks a JDK. It means the specific JVM that is running Maven right now has no compiler inside it. Your terminal and Maven can be using two different Javas, and they usually are when you see this.

My first instinct, years ago, was to reinstall the JDK. It was already installed. Maven wasn't using it.

## Ask Maven which Java it's sitting on

One command settles it:

```bash
mvn -v

```

Read the `runtime:` part of the `Java version` line, not the version number. Here's my lab, with `JAVA_HOME` pointed at a runtime that has no compiler:

```log
$ JAVA_HOME=/tmp/claude-0/lab/jre-21 mvn -v
Apache Maven 3.9.11 (3e54c93a704957b63ee3494413a2b544fd3d825b)
Maven home: /opt/maven
Java version: 21.0.13.1, vendor: Ubuntu, runtime: /tmp/claude-0/lab/jre-21
Default locale: en_US, platform encoding: UTF-8

```

Version 21, perfectly happy. Maven itself runs fine on a JRE (a Java runtime without the development tools), which is why nothing complains until the compile step. Then check that folder:

```bash
ls "<runtime-from-mvn-v>/bin/javac"                     # a JDK has this file
"<runtime-from-mvn-v>/bin/java" --list-modules | grep jdk.compiler   # and this module

```

If either comes back empty, that's your answer. On Windows, `dir "<runtime>\bin\javac.exe"` does the same job.

Where does `mvn` get that runtime? The `bin/mvn` script in Maven 3.9 uses `$JAVA_HOME/bin/java` when `JAVA_HOME` is set and falls back to whatever `java` is on `PATH` only when it isn't. So the classic setup for this error is a `PATH` that finds a JDK and a `JAVA_HOME` that points at a JRE. Your terminal and your build each picked one. If the `JAVA_HOME` part is fuzzy, [the JAVA\_HOME post](https://ggorantala.dev/set-java-home-windows-macos-linux/?ref=ggorantala.dev) walks through who reads it and who ignores it.

## A compiler-less runtime, on purpose

You can watch the exact check Maven makes, without Maven. I did this in Ubuntu 24.04 with OpenJDK 21.0.13.1.

**Step 1: cut a runtime without the compiler.** `jlink` builds a Java runtime from a list of modules. Leave out `jdk.compiler` and everything that depends on it:

```bash
J=/usr/lib/jvm/java-21-openjdk-amd64
MODS=$($J/bin/java --list-modules | sed 's/@.*//' \
  | grep -v -E '^(jdk.compiler|jdk.jshell|jdk.javadoc|jdk.jdeps|jdk.jlink|jdk.jpackage|jdk.internal.opt|jdk.internal.ed|jdk.internal.le|jdk.editpad|jdk.jdi|jdk.hotspot.agent|jdk.jstatd|jdk.jartool)$' \
  | paste -sd, -)
$J/bin/jlink --add-modules "$MODS" --output ./jre-21 --strip-debug --no-header-files --no-man-pages

```

That gave me a 130 MB runtime with `java`, `jcmd`, `keytool` and friends in `bin`, and no `javac`. Note the one thing it does still have: the `java.compiler` module. Hold that thought.

**Step 2: ask each runtime for its compiler.** This is the call the Maven compiler plugin makes when it compiles in-process:

```java
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;

public class Probe {
    public static void main(String[] args) {
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); // the same call Maven's in-process compile makes
        System.out.println("java.home = " + System.getProperty("java.home"));
        System.out.println("compiler  = " + compiler);
        System.out.println("jdk.compiler module present: "
                + ModuleLayer.boot().findModule("jdk.compiler").isPresent());
    }
}

```

**Step 3: run it on both.**

```log
$ /usr/lib/jvm/java-21-openjdk-amd64/bin/java Probe.java
java.home = /usr/lib/jvm/java-21-openjdk-amd64
compiler  = com.sun.tools.javac.api.JavacTool@58c1c010
jdk.compiler module present: true

$ javac -d out Probe.java && ./jre-21/bin/java -cp out Probe
java.home = /tmp/claude-0/lab/jre-21
compiler  = null
jdk.compiler module present: false

```

That `null` is the whole error. Expected time: about a minute, most of it `jlink`.

I tried one thing first that didn't work, and it's worth knowing. Running `./jre-21/bin/java Probe.java` (source-file mode, no `javac` step) fails before the probe even starts:

```log
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.InternalError: Module jdk.compiler not in boot Layer

```

Source-file mode compiles your file in memory with the same compiler, so on a JRE it can't start at all. Different message, same missing module. Compile on the JDK, run on the JRE.

**Teardown:** `rm -rf jre-21 out Probe.java`. Nothing else was changed.

## Why it broke, the simple version

The JVM that runs Maven was a JRE, or a trimmed runtime. The compiler plugin asked that JVM for its built-in compiler, got nothing back, and printed the message. Point Maven at a JDK and it goes away.

## Where the message comes from

The text isn't from Maven core. It's from plexus-compiler, the library the 3.x compiler plugin uses. In [JavaxToolsCompiler.java](https://github.com/codehaus-plexus/plexus-compiler/blob/plexus-compiler-2.18.1/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavaxToolsCompiler.java?ref=ggorantala.dev), `compileInProcess` gets its compiler from `ToolProvider.getSystemJavaCompiler()`. When that returns `null`, it doesn't throw. It builds a compiler error message with this exact text and returns a failed result, which is why Maven reports it as `COMPILATION ERROR` and "Compilation failure", as if your code had a typo. The code is the same at tag 2.15.0 and at 2.18.1, the newest on Central as I write.

Now that thought I asked you to hold. `ToolProvider` lives in the `java.compiler` module, which is only the API. The actual compiler, `com.sun.tools.javac`, lives in `jdk.compiler`. A runtime can have the first without the second, and that's exactly my lab: the API loads fine, finds no implementation and returns `null`. The [Java Compiler API guide](https://openjdk.org/groups/compiler/guide/compilerAPI.html?ref=ggorantala.dev) describes this split; the lab makes it concrete.

The surprise came when I checked where that module comes from on Ubuntu. I expected `openjdk-21-jdk-headless` to bring it. It doesn't:

```log
$ dpkg -S /usr/lib/jvm/java-21-openjdk-amd64/lib/modules
openjdk-21-jre-headless:amd64: /usr/lib/jvm/java-21-openjdk-amd64/lib/modules
$ jimage list /usr/lib/jvm/java-21-openjdk-amd64/lib/modules | grep -c '^Module: jdk.compiler'
1

```

The runtime image shipped by the *JRE* package already contains `jdk.compiler`. The JDK package adds the `javac` launcher, `jmods` and the other tools. So on Ubuntu, a JRE-only install fails with `javac: command not found` in a shell, while Maven's in-process compile could still find a compiler. Other JREs (vendor JRE builds, slim container images, anything made with `jlink`) may not include it. Don't guess. `java --list-modules | grep jdk.compiler` on the runtime Maven uses is the test that counts.

The message changes with the plugin generation. The 4.x compiler plugin (still beta, 4.0.0-beta-5 as of this writing) doesn't use plexus-compiler; the [4.0.0-beta-5 source](https://github.com/apache/maven-compiler-plugin/blob/maven-compiler-plugin-4.0.0-beta-5/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java?ref=ggorantala.dev) fails with `No such "javac" compiler.` instead. Same cause.

## Fixing No compiler is provided, wherever Maven runs

The cause is always the JVM Maven runs on, so the fix is always "give Maven a JDK". Where you set that depends on who launched Maven.

### Terminal (Linux, macOS, Windows)

Point `JAVA_HOME` at the JDK's root folder, the one that contains `bin/javac`:

```bash
# Linux
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
# macOS
export JAVA_HOME="$(/usr/libexec/java_home -v 21)"
mvn -v   # the runtime: line must now be that folder

```

On Windows, set `JAVA_HOME` under System Properties > Environment Variables to something like `C:\Program Files\Eclipse Adoptium\<jdk-folder>`, then open a **new** window. If only a JRE is installed, install a JDK first: `sudo apt install openjdk-21-jdk-headless` on Debian/Ubuntu, `sudo dnf install java-21-openjdk-devel` on Fedora/RHEL (the `-devel` package is the JDK there).

### Eclipse

Eclipse runs Maven builds with the JRE in Window > Preferences > Java > Installed JREs, and Eclipse often registers a JRE there by default. Click Add, pick your JDK's folder, and tick it as the default. Check the Run As > Maven build configuration too: its JRE tab can override the default.

### IntelliJ IDEA

IntelliJ picks Maven's JVM in Settings > Build, Execution, Deployment > Build Tools > Maven > Runner, in the JRE field. Set it to a JDK (or "Use Project JDK" with a JDK as the project SDK).

### CI and Docker

The usual container trap is installing Maven on top of a `-jre` image. Build on a JDK image (an `eclipse-temurin:21-jdk` tag, or a `maven:3.9-eclipse-temurin-21` tag), and keep the `-jre` image for the stage that only runs the jar. On GitHub Actions, `actions/setup-java` installs a JDK by default; it's a `java-package: jre` line that would give you this error.

### Things that look like fixes and aren't

`<fork>true</fork>` often makes the error vanish, and that's what worries me about it. With forking, plexus looks for `javac` next to the running JVM, then under `JAVA_HOME`, and if both fail it logs `Unable to autodetect 'javac' path, using 'javac' from the environment.` and runs whatever `javac` is on `PATH`. Your build now compiles with one JDK and runs Maven on another, and nothing in the log says which. Pointing `<executable>` at a hard-coded `javac` path has the same problem, plus it breaks on every other machine.

Copying `tools.jar` into the JRE was the advice for Java 8\. There's no `tools.jar` since JDK 9, so ignore any answer that mentions it.

## One JDK per build, written down

The structural fix is to stop letting the environment decide. Gradle already behaves this way; I ran the same compiler-less runtime against Gradle 8.14.3 and got a clear refusal instead of a fake compile error:

```log
$ JAVA_HOME=/tmp/claude-0/lab/jre-21 gradle --no-daemon -q compileJava --offline
* What went wrong:
Could not determine the dependencies of task ':compileJava'.
> Could not resolve all dependencies for configuration ':compileClasspath'.
   > Failed to calculate the value of task ':compileJava' property 'javaCompiler'.
      > Toolchain installation '/tmp/claude-0/lab/jre-21' does not provide the required capabilities: [JAVA_COMPILER]

```

With a `java { toolchain { languageVersion = JavaLanguageVersion.of(21) } }` block, Gradle goes looking for a JDK 21 on its own and doesn't care what `JAVA_HOME` says.

Maven's version of this is Toolchains: declare your JDKs once in `~/.m2/toolchains.xml`, add the toolchains plugin to the build, and the compiler plugin forks the `javac` from that JDK. Then pin the release you compile for:

```xml
<properties>
  <maven.compiler.release>21</maven.compiler.release>
</properties>

```

If you'd rather not run toolchains, add a Maven Enforcer `requireJavaVersion` rule so the build fails at validate time with a sentence you understand, before it ever reaches the compiler. [The post on switching Java versions](https://ggorantala.dev/switch-java-versions-multiple-jdks/?ref=ggorantala.dev) covers keeping several JDKs side by side without this kind of drift.

## The first line of every CI log

Make every pipeline print its Java before doing anything else:

```bash
mvn -v
"$JAVA_HOME/bin/javac" -version || { echo "JAVA_HOME is not a JDK: $JAVA_HOME"; exit 1; }

```

The second line costs nothing and turns a confusing compile error into a sentence that names the folder.

On versions: this message has read the same in every plexus-compiler release I checked, it shows up with any JRE from 8 to 25, and it only changes if you move to the 4.x compiler plugin (`No such "javac" compiler.`). What does change on upgrade is folder names. A `JAVA_HOME` that points at `jdk-21.0.4` keeps "working" after that folder is gone if a JRE sits at a similar path, so re-run `mvn -v` after every JDK update. If the build then breaks with a class-file version error instead, that's [UnsupportedClassVersionError](https://ggorantala.dev/unsupportedclassversionerror/?ref=ggorantala.dev) territory.

For the record, what I checked: the throw site in plexus-compiler at two tags, the 4.x replacement message, the `bin/mvn` script's `JAVA_HOME` logic, a JDK vs a jlink runtime on OpenJDK 21.0.13.1, Gradle 8.14.3's behaviour on the same runtime, and which Ubuntu package ships the compiler module. Not Eclipse or IntelliJ themselves; those steps come from their docs.

## What to remember

- The error is about the JVM *running Maven*, not your machine. `mvn -v` shows which one, on the `runtime:` part of the line.
- `java -version` and `javac -version` in a terminal prove nothing about Maven when `JAVA_HOME` is set.
- Test a runtime with `ls bin/javac` and `java --list-modules | grep jdk.compiler`.
- `<fork>true</fork>` can hide the problem by quietly using a different `javac`. Fix `JAVA_HOME` or the IDE's Maven JRE instead.
- Long term, toolchains (Maven or Gradle) take the guessing out.

## Searches that land here

### How do I fix "No compiler is provided in this environment" in Maven?

Run `mvn -v` and look at the runtime path. If that folder has no `bin/javac`, point `JAVA_HOME` at a JDK (or set the IDE's Maven JRE to one) and rerun. Installing a JDK only helps if Maven actually uses it.

### How do I know if JAVA\_HOME points to a JRE instead of a JDK?

Run `"$JAVA_HOME/bin/javac" -version` (on Windows, `"%JAVA_HOME%\bin\javac" -version`). A JDK answers with a version; a JRE says the file doesn't exist. Gradle reports it as `does not provide the required capabilities: [JAVA_COMPILER]` and Maven as "No compiler is provided".

### Why does java -version show a different version than my Maven build uses?

The `java` command comes from `PATH`, while `mvn` uses `JAVA_HOME` whenever it's set, and IDEs use their own JDK setting. Three sources, three possible answers. `mvn -v` shows what Maven picked; [the wrong-Java-version post](https://ggorantala.dev/wrong-java-version-path-order/?ref=ggorantala.dev) covers fixing the `PATH` side.

### Does setting fork to true fix it?

It hides it. A forked compile runs a `javac` found next to the JVM, under `JAVA_HOME`, or on `PATH`, so the build may pass with a different JDK than the one running Maven. Fix the runtime instead.