Here's a really good example of NoClassDefFoundError
public class NoClassDefFoundErrorDemo {
public static void main(String[] args) {
try {
// The following line would throw ExceptionInInitializerError
SimpleCalculator calculator1 = new SimpleCalculator();
} catch (Throwable t) {
System.out.println(t);
}
// The following line would cause NoClassDefFoundError
SimpleCalculator calculator2 = new SimpleCalculator();
}
}
When the code throws, then the initialization in the bottom will not succeed and will throw NoClassDefFoundError
, which makes sense.
Here's the question (actually a problem)
I have a Servlet-based Jar classloader that loads Jar from file system at runtime and is experiencing this similar error, the question would be, is there a way to get around the error without restarting the whole server? Or even renaming the package for the classes in the Jar?