Java NotFoundError Variants
Java has several "not found" errors, each with different root causes. Here's how to distinguish and fix them.
ClassNotFoundException
Thrown when Class.forName() or ClassLoader.loadClass() can't find a class at runtime:
// Error: ClassNotFoundException: com.mysql.cj.jdbc.Driver
// Fix: add the dependency
// Maven:
// <dependency>
// <groupId>com.mysql</groupId>
// <artifactId>mysql-connector-j</artifactId>
// <version>8.2.0</version>
// </dependency>
// Then the driver auto-registers, no need for:
// Class.forName("com.mysql.cj.jdbc.Driver");NoClassDefFoundError
Different from ClassNotFoundException — the class existed at compile time but is missing at runtime:
# Check if the JAR is in the classpath
java -cp "lib/*:app.jar" com.myapp.Main
# Or use -verbose:class to see where classes load from
java -verbose:class -jar app.jar 2>&1 | grep MyClassFileNotFoundException
// BAD — path is relative to working directory, not the JAR
new FileInputStream("config.properties");
// GOOD — load from classpath
InputStream is = getClass().getResourceAsStream("/config.properties");
if (is == null) {
throw new FileNotFoundException("config.properties not found in classpath");
}Spring Boot Resource Loading
@Value("classpath:templates/email.html")
private Resource emailTemplate;
// Or
Resource resource = new ClassPathResource("data/seed.json");
try (InputStream is = resource.getInputStream()) {
// Process the file
}Bugsly captures all three error types with the class name, classpath information, and the calling code location — everything needed to diagnose the missing dependency.
Try Bugsly Free
AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.
Get Started FreeRelated Articles
What Is Site Reliability Engineering (SRE)?
Learn what Site Reliability Engineering is, core SRE principles including SLOs, error budgets, and toil reduction, and how SRE improves reliability.
Read moreFix NotFoundError in Rust
Resolve file not found and module resolution errors in Rust projects, covering mod declarations, Cargo dependencies, and path handling.
Read moreHow to Fix Type Mismatch in Vue.js
Struggling with Type Mismatch in Vue.js? This guide explains why it happens and how to resolve it quickly.
Read moreFix Load Balancer Error in Django
Troubleshoot Django errors behind load balancers including ALLOWED_HOSTS, CSRF, SECURE_PROXY_SSL_HEADER, and health check setup.
Read more