ClassNotFound does not always mean class not found

A Java ClassNotFound exception does not always mean that a class could not be found on the classpath. It seems that sometimes it can mean that the class was actually found 2 or more times – a conflict in the classloader.

Recently, while developing a portlet for WebSphere Portal, I got the following exception:

Caused by: java.lang.ClassNotFoundException: javax.el.ELException

My portlet ran fine in my local development environment, but when I deployed it to Production, it crapped out. This is because I had included JSTL jar files in my portlet’s WEB-INF/lib folder. As it turns out, those jar files, or similar ones, were already somewhere on the classpath in the Production environment.

So…It seems that the class was actually found – just more times than expected. It is as if the classloader cancels them all out if it finds duplicates or conflicts. This, in turn, can lead to the ClassNotFound message, which in that case is somewhat misleading.

Just something to keep in mind.