Java / JVM

java.lang.ClassNotFoundException / NoClassDefFoundError

Java, JVM

java.lang.ClassNotFoundException — or NoClassDefFoundError — for com.example.Foo.

What it means (root cause)

The class is not on the runtime classpath — a missing dependency in the build, a wrong JAR, or a module/version mismatch between compile and run.

The symptom developers actually see: java.lang.ClassNotFoundException — or NoClassDefFoundError — for com.example.Foo.

How to avoid it: Pin dependency versions and let the build tool assemble the runnable artifact; verify the manifest Class-Path.

Step-by-step fix

Concrete, ordered steps from the dataset. Apply them in order; each line is a verified action, not generic advice.

  1. 1Add the missing dependency to your build (Maven/Gradle) and rebuild; verify it lands in the runnable artifact.
  2. 2Confirm the runtime classpath matches compile time — no stray older JAR shadowing the class.
  3. 3For modules, ensure the package is declared in module-info.java and exported/required correctly.

Where this error appears

Languages, frameworks, and runtimes where this error is observed (from the 2026 DevFixPro error dataset, retrieved 2026-08-29):

JavaJVM

JVM (Java/Kotlin/Scala). ClassNotFoundException = load-time missing; NoClassDefFoundError = link-time missing (present at compile, absent at run).

How to prevent it & common questions

Practical prevention plus the questions developers ask most about this error.

What does "java.lang.ClassNotFoundException / NoClassDefFoundError" mean?

The class is not on the runtime classpath — a missing dependency in the build, a wrong JAR, or a module/version mismatch between compile and run.

Which environments are affected by java.lang.ClassNotFoundException / NoClassDefFoundError?

Java, JVM

How do I fix java.lang.ClassNotFoundException / NoClassDefFoundError?

Add the missing dependency to your build (Maven/Gradle) and rebuild; verify it lands in the runnable artifact. Confirm the runtime classpath matches compile time — no stray older JAR shadowing the class. For modules, ensure the package is declared in module-info.java and exported/required correctly.

How do I prevent java.lang.ClassNotFoundException / NoClassDefFoundError?

Pin dependency versions and let the build tool assemble the runnable artifact; verify the manifest Class-Path.

ClassNotFoundException vs NoClassDefFoundError?

ClassNotFoundException means the loader never found it; NoClassDefFoundError means it was present at compile but absent at runtime (often a missing dependency in the artifact).

It compiles but fails at runtime?

The classpath at run differs from compile. Rebuild the artifact with the dependency included and check the manifest Class-Path.

Related DevFixPro tools

Real, browser-only utilities on DevFixPro that help while you work through this issue. These are navigation aids, not a substitute for the fix above.

● Data updated 2026-08-29

Sources & attribution

  • Error records aggregated from Google Search Console query gaps (2026-05-21~2026-08-18) for devfixpro.com, plus official framework docs (MDN, Node.js docs, Python docs, Go.dev, Rust book, Oracle Java docs, Docker docs, npm docs). Source dataset retrieved 2026-08-29. License: CC BY 4.0 — attribute DevFixPro (devfixpro.com).
  • Official reference: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/ClassNotFoundException.html
  • All cause, environment, fix and prevention text on this page is taken verbatim from the DevFixPro 2026 error dataset. DevFixPro does not invent root causes or fixes.
How this java.lang.ClassNotFoundException / NoClassDefFoundError page is built

Each error page is generated from a single record in the DevFixPro 2026 error dataset. The meaning, root cause, environments, fix steps, prevention, and official references are copied verbatim from that dataset and its official-doc sources; related-error links are computed from the error's category and explicit peer list. No root cause or fix is invented. The retrieval date for this dataset is 2026-08-29.

← Back to all errors