Sunday, December 03, 2006

Java Classloader Mystery

If you are writing system software, then you have to worry or deal with classloaders. Here is a nice blog entry on Classloaders from someone at Sun.
Understanding Java class loading

Now, for the second part of the article,
Understanding Classloading Part 2

If you are having scoped deployments in JBoss, follow this good post from Bill Burke
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4028665
Please do not ever use Class.forName() in any of your code, but instead use Thread.currentThread().getContextClassLoader().loadClass().

Reason? The reason is scoped classloaders. Class.forName() will use the calling class's classloader. So, if your code resides in a jbossesb.jar someplace, your code will use the ESB server's (JBoss) classloader, rather than the scoped one of your ESB deployment. For example, if your actions are deployed in a scoped .esb file, then it will not run.

No comments: