Skip to content
Latchkey

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.

mvn output
[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:compile

Common 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.

.github/workflows/ci.yml
- 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.

Terminal
# verify JAVA_HOME is a real JDK home
echo "$JAVA_HOME"
"$JAVA_HOME/bin/javac" -version

How to prevent it

  • Use setup-java or 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 -bootclasspath unless cross-compiling deliberately.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →