Causes and solutions of classnotfoundexception / NoClassDefFoundError

A NoClassDefFoundError is an Error, while a ClassNotFoundException is an exception. In Java, an Error and an exception are handled differently. You can recover from an exception but you shouldn’t try to recover from an Error.
ClassNotFoundException causes:
Java supports dynamically loading classes using the Class.forName method. Passing the Class name of any Class as an argument to the method will cause the Class to be loaded into the JVM memory. If the Class is not found in the classpath, then a ClassNotFoundException is thrown at runtime.
ClassNotFoundException solve
Solving this problem requires ensuring that the required class, along with its dependent packages, exists in the classpath. A common problem is that the class name is misspelled.
Another cause of ClassNotFoundException is that when a class has already been loaded into memory by one class loader, another class loader tries to dynamically load the class from the same package. This can be avoided by controlling the dynamic classloading process.
NoClassDefFoundError causes:
If the JVM or ClassLoader instance tries to load a class (either through normal method calls, or by using new to create a new object), the class definition is not found. The class you are looking for exists at compile time but cannot be found at run time.
The problem may be caused by missing classes during the packaging process, or by corrupted or tampered JAR packages.
NoClassDefFoundError solve
The solution to this problem is to look for classes that are in the classpath at development time but not at run time.


Read More: