java.lang.ClassNotFoundException / NoClassDefFoundError
The JVM couldn’t find a class on the classpath at runtime.
Could not find or load main class 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/testused at runtime - Version conflicts between libraries
- JDBC driver not included
- Static initializer threw an exception earlier (NoClassDefFoundError)
⚡ Quick fix
- Check the dependency is in the built artifact (
jar tf app.jar | grep ClassName) - Fix Maven/Gradle scopes
- Run
mvn dependency:tree/gradle dependenciesto find conflicts - Look earlier in logs for ExceptionInInitializerError
Detailed fix by platform
Java
- Use the Spring Boot / Shadow plugin to build an executable JAR that includes dependencies.
How to diagnose
- Class — Which class and which JAR should provide it?
- Artifact — Is it in the deployed classpath?
- 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:
Similar errors
Most viewed in Java
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 14 Oct 2026