November 24, 2026 ยท Guide

Maven Fails With No Compiler Error After a JDK Swap: Reading the Toolchain Log First

The build came back green two days ago. Today it says COMPILATION ERROR with no file, no line, no message. Nothing changed in the source tree. What changed was JAVA_HOME, pointed at a newer JDK after the old one got patched out from under us. Maven stopped finding javac and reported the failure as if the compiler had run and found bad code.

This is the most misleading class of Maven failure we deal with, and the fix almost never lives in the POM. It lives in the tool the build assumed was there. Before touching pom.xml, read the toolchain log. It usually names the real problem in the first twenty lines.

What the “no compiler” error actually means

Maven does not compile Java itself. It hands that job to a compiler plugin, which by default runs the javac it can find on the JVM running Maven. After a JDK swap, three things can be true at once and only one of them is your code:

  • JAVA_HOME points at a directory that is not a JDK, or a half-removed one, so javac is absent.
  • The compiler plugin is pinned to a version that resolves the fork in a way the new JDK no longer likes.
  • A toolchain file names an older JDK that got deleted.

Maven reports all three the same way: an empty compilation failure. The stack trace you want is buried above the summary line, and it is usually the plugin telling you it could not locate the executable.

Read the log before you read the POM

Run the build with the errors kept and the debug output on, and pipe it to a file you can actually scroll:

mvn -e -X clean compile > build.log 2>&1

Then search the log rather than reading it linearly. Three strings do most of the work:

  • javac shows every place the build looked for the compiler and whether it found it.
  • toolchain shows whether a toolchain was requested and what path it resolved to.
  • JAVA_HOME shows the JDK the plugin believed it was using.

On Windows, filtering a log is a one-liner with findstr or Select-String. When we keep build logs around for a week or more, the built-in forfiles utility handles the housekeeping: it walks a directory and acts on files by age. Its @fdate and @fname variables let a short script list or delete only the stale logs without touching the ones from today’s build. No third-party cleaner needed.

If the log shows javac resolution failing outright, you have your answer and the POM is innocent. If it shows a path under a JDK you thought was gone, the toolchain file is lying to you.

The toolchains file is the usual culprit

Plenty of teams set up ~/.m2/toolchains.xml once, years ago, to pin the build to a specific JDK. Then the JDK gets uninstalled during cleanup. The file still points there. Maven still trusts it. The build fails with no compiler error because the compiler it was told to use does not exist.

Open the toolchains file and compare each <jdkHome> against what is actually installed. On Windows, verify with the same command the build will use:

where javac
"%JAVA_HOME%\bin\javac" -version

If where javac returns nothing, JAVA_HOME is wrong or PATH is stale. Point JAVA_HOME at a real JDK root, refresh the terminal, and rerun. The compiler error tends to vanish the moment javac -version prints a version.

When the JDK moved but Maven did not notice

The classic mistake after a swap: updating the system environment variable while an existing terminal session still holds the old value. Maven inherits the environment of the shell that launched it. Close the window, open a new one, confirm echo %JAVA_HOME% shows the new path, and build again.

If your shell is a wrapper, IDE terminal, or build daemon, it may cache the environment even across new windows. Kill the daemon, reopen, retry. We have watched a thirty-second fix turn into an afternoon because a background Maven process was serving the old PATH.

Confirm the compiler plugin is not the problem

Once javac resolves, the error should clear. If it does not, check which version of the compiler plugin the build uses. Old plugin versions resolve the compiler differently than current ones and can choke on a newer JDK. The fix is a version bump, not a code change:

mvn -X compile 2>&1 | findstr /I "maven-compiler-plugin"

Read the version the log reports, then pin that plugin to a current release in the POM. The build file stops being a guess and starts being a decision.

Stop trusting the summary line

The reason this failure wastes so much time is that Maven prints the same closing line whether the code was wrong or the tool was missing. They are completely different problems and they get the same headline. The log knows the difference. It always did. You just have to read it before you start editing the POM.

Our rule for any build that fails with an empty message: read the toolchain resolution first. The POM is almost never the place to start.