Monday, February 23, 2009

JBoss 4.2 class loading problems

By default Jboss 4.2 does non-scoped class loading i.e. all EARs share the same class loader. This is non-J2EE but default way of doing things in JBoss. If you want an EAR to have its own class-loader (you wan different versions of the same library in different EARs), you need to include jboss-app.xml with following configuration:


<jboss-app>
<loader-repository>
${package-name}:archive=${unique-name}
</loader-repository>
</jboss-app>

An example:
<jboss-app>
<loader-repository>
com.shital:archive=test1
</loader-repository>
</jboss-app>


This needs to be done for each EJB which needs a scoped class loader. Make sure that unique-name in above example is unique for each EAR!

This file should be packaged in the same dir as application.xml.