A JSP code to debug class loader issues

Class Loader is one of the complex concept/design to understand in Java programming. On the initial days working with Tomcat and Desktop application there is not much class loading issues. From EJB days class loading became complex by specification and implementation. Seems JavaEE 5 tries to simplify the class loading specification but I don’t know much about that.

To add to JavaEE specification complexity vendors provide their default libraries like log4j which inherits into application without developer knowledge. Of course they are giving ways to configure to avoid such class loader conflict but to figure that will take lot of time. For example OracleAS made log4j as default component for all application in later version they removed. The class loader issue generally doesn’t give a good error message most of the it says Linkage error or NoClassDefFound or ClassCastException. These errors are not always usefult to find the root cause.

Recently I wrote a jsp page to debug class loader issue. This jsp page doesn’t tell you how to fix the problem but it might help you to figure out where the problem could be. Even with this jsp still you need better understanding on class loader to fix if there are any issues. This jsp page gives two information about the class loader.

a) The location of the class/resource is referred like jar file physical location. Sometime App Server might ignore your jar file and refers its default jar. You can observe those behavior by seeing the jar file location. Sometime you might have two different version of same library in your classpath.

b) ClassLoader’s class name. It might help you to figure which class loader loads the class.

JSP file: https://github.com/venkatsalem/workspace/blob/master/ad-auth/src/main/webapp/classloader.jsp

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: