ClassNotFoundException
JavaFATALNotableClasspath
Class not found on classpath
Quick Answer
Add the missing JAR as a dependency in Maven/Gradle and verify the class name is spelled correctly.
What this means
Thrown when an application tries to load a class by name but the class is not on the classpath at runtime.
Why it happens
- 1Required JAR not declared in pom.xml or build.gradle
- 2Typo in the class name string passed to Class.forName
Fix
Add Maven dependency
Add Maven dependency
<dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>42.7.0</version> </dependency>
Why this works
Maven downloads the JAR and adds it to both compile and runtime classpaths.
Code examples
Triggerjava
Class.forName("com.example.Missing"); // ClassNotFoundExceptionSafe dynamic loadjava
try {
Class<?> c = Class.forName(className);
} catch (ClassNotFoundException e) {
log.error("Driver not on classpath: {}", className);
}JDBC driver loadjava
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection(url, user, pass);Same error in other languages
Sources
Official documentation ↗
Java SE Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev