Maven "Cannot find the class file for java.lang.Object" - Fix Broken JDK
The compiler could not load java.lang.Object - the root of every Java type. That only happens when the JDK itself is broken or incomplete: a missing core module image (lib/modules), a truncated install, or a bootclasspath pointing at the wrong place.
What this error means
Compilation fails with cannot access Object / Cannot find the class file for java.lang.Object, or bad class file for a core JDK class. The error is about the JDK, not your code - your sources never get a chance to compile.
[ERROR] COMPILATION ERROR :
[ERROR] error: cannot access Object
bad class file: ... cannot find the class file for java.lang.Object
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compileCommon causes
Broken or incomplete JDK install
A truncated download, a partially-extracted archive, or a stripped image missing lib/modules (or rt.jar on JDK 8) means the compiler cannot load the core classes.
Wrong bootclasspath or JAVA_HOME
A manually overridden -bootclasspath, or a JAVA_HOME pointing at a directory that is not a real JDK home, leaves the core library unreachable.
How to fix it
Reinstall a clean, complete JDK
Provision a full JDK from a trusted distribution and confirm it is intact.
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- run: |
java -version
ls "$JAVA_HOME/lib/modules" # core image must exist (JDK 9+)Remove a bad bootclasspath override
Let the compiler use the JDK’s own core library - do not override the bootclasspath unless you truly mean to.
# verify JAVA_HOME is a real JDK home
echo "$JAVA_HOME"
"$JAVA_HOME/bin/javac" -versionHow to prevent it
- Use
setup-javaor a known-good JDK base image rather than ad hoc downloads. - Verify the JDK is complete (
java -version, core module image present) early in CI. - Avoid overriding
-bootclasspathunless cross-compiling deliberately.