ClassNotFoundException Java Origin: Application & API Last updated 14 Oct 2026

java.lang.ClassNotFoundException / NoClassDefFoundError

The JVM couldn’t find a class on the classpath at runtime.

Exact message you may see Could not find or load main class
Seen on: Java

Meaning

ClassNotFoundException happens when code loads a class by name (JDBC drivers, reflection) and it isn’t on the classpath. NoClassDefFoundError means the class existed at compile time but is missing (or failed static init) at runtime.

Common causes

  • Dependency missing from the runtime classpath / fat JAR
  • Dependency scope provided/test used at runtime
  • Version conflicts between libraries
  • JDBC driver not included
  • Static initializer threw an exception earlier (NoClassDefFoundError)

⚡ Quick fix

  1. Check the dependency is in the built artifact (jar tf app.jar | grep ClassName)
  2. Fix Maven/Gradle scopes
  3. Run mvn dependency:tree / gradle dependencies to find conflicts
  4. Look earlier in logs for ExceptionInInitializerError

Detailed fix by platform

Java

  1. Use the Spring Boot / Shadow plugin to build an executable JAR that includes dependencies.

How to diagnose

  1. Class — Which class and which JAR should provide it?
  2. Artifact — Is it in the deployed classpath?
  3. Init — Earlier static init failure?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

0x8007007E — 0x8007007E: The specified module could not be found (Windows)0x8007007EClass not found — PHP Fatal error: Uncaught Error: Class "X" not found (PHP)Class not foundComposer conflict — Your requirements could not be resolved to an installable set of packages. (PHP)Composer conflictCould not resolve — Gradle: Could not resolve all files for configuration / Could not resolve dependency (Android)Could not resolveDEP0040 — DeprecationWarning: The `punycode` module is deprecated (DEP0040) (Node.js)DEP0040Dependency requires compileSdk — Dependency 'androidx.x:1.y' requires libraries and applications that depend on it to compile against version 34 or later of the Android APIs (Android)Dependency requires c…Duplicate class — Duplicate class X found in modules A and B (Android)Duplicate classFileNotFoundException assembly — Could not load file or assembly 'X, Version=…' or one of its dependencies (.NET)FileNotFoundException…ClassNotF…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.