# java.lang.ClassNotFoundException / NoClassDefFoundError

**Code:** `ClassNotFoundException` · **Category:** Java · **Seen on:** Java

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/java/classnotfoundexception)
