Monday, 1 November 2010

Trouble shooting class errors

1) You can turn on JVM switch to dump out all loaded classes

2) NoSuchMethodError? So where is that class coming from?

In your app, before the runtime exception, place this code:

while (urls.hasMoreElements()) {
System.out.println("******************* " + urls.nextElement());

Then determine class loader:

System.out.println("$$$$$$$$$$$ " + org.springframework.core.type.AnnotationMetadata.class.getClassLoader());
On a startup listener in your app (for example), type:

3) So I see the class getting loaded from a rogue jar file, but where is this jar file coming from? What is the classpath? Running jetty with -X dumps out all jar files in the classpath, and here we spot the rogue one..... It happens to come from a maven dependency....

No comments: