ClassNotFoundException ☕ Java

java.lang.ClassNotFoundException / NoClassDefFoundError

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

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