Troubleshooting Java classloader or class loading issues -- JBoss example
Every Java developer faces the following issue from time to time.
In JBoss 4.x versions, you need to turn off the PARENT_FIRST delegation mode in its jboss-web.xml descriptor file.
<jboss-web> <!-- Sets the isolation scope for the WAR. We are now using a parent LAST policy for the war classloader. Meaning that classes/jars in the war take precedence over those provided by the EAr & App Server. --> <loader-repository> maya.macquarie.com:loader=my-webservices.war <loader-repository-config>java2ParentDelegation=false</loader-repository-config> </loader-repository> </jboss-web>
In JBoss 5 on wards, you need to have a jboss-classloading.xml in my_app.ear/META-INF as shown below
<classloading xmlns="urn:jboss:classloading:1.0" domain="my_app.ear" export-all="NON_EMPTY" import-all="true" parent-first="false"> </classloading>
- by setting the domain, we are specifing that the my_app.ear application participate in its own domain my_app.ear.
- by setting parent-first to false, we are essentially declaring that EARs classes be preferred over JBoss’s
JBoss AS 7 follows a real modular approach deprecating all earlier approaches. The server bootstrap libraries are now located at the root of the application server. The jboss-deployment-structure.xml needs to be placed within the META-INF folder of the EAR or inside WEB-INF of your war file.
<jboss-deployment-structure> <sub-deployment name="my_app.war"> <dependencies> <module name="org.apache.log4j" /> </dependencies> </sub-deployment> </jboss-deployment-structure>
You can apply exclusions
<jboss-deployment-structure> <deployment> <exclusions> <module name="javax.faces.api" /> <module name="com.sun.jsf-impl" /> </exclusions> <dependencies> <module name="javax.faces.api" slot="2.0"/> <module name="com.sun.jsf-impl" slot="2.0"/> </dependencies> </deployment> </jboss-deployment-structure>
This is only a general discussion. Please refer to the relevant JBoss documentation for more options and appropriate solutions.