JBoss AS 5.1.0.GA Classloading Help
garethwebbley Nov 7, 2009 6:12 PMI have an ear file containing 2 war files. I have structured the files so that common jars appear in the ear file root directory and jars that are specific to the individual war files are included in the appropriate war file. Each war file contains a MANIFEST.MF referencing the jars contained in the ear file that they need to use.
I am using spring to configure a shared application context which is the parent of application contexts in the war files.
I have run into a problem when trying to inject a bean from the shared context into a bean defined in war 2 if the same bean is injected into a bean defined in war 1. It appears that the class file is loaded by war 1's class loader rather than the ear classloader even though the file is from a jar in the ear file. I was expecting this class to be loaded by the class loader of the ear but instead it was loaded by the class loader of war 1. I can tell this by using the jmx-console classloader MBean and running the findClassLoaderForClass operation.
I have spent some time googling for details of class loading in JBoss 5 but unfortunately the available resources are quite limited so I resorted to looking through the source code. I found references to the jboss-classloading.xml files so I have tried creating some of these files for my ear and war files but I am still having no luck. Here are my attempts :-
In the EAR file -
<classloading xmlns="urn:jboss:classloading:1.0"
name="ptd-ear-1.0-SNAPSHOT.ear"
domain="ptd-ear-1.0-SNAPSHOT.ear"
export-all="NON_EMPTY"
import-all="true"
parent-first="false">
In war file 1 -
<classloading xmlns="urn:jboss:classloading:1.0"
name="ptd-jsf-1.0-SNAPSHOT.war"
domain="ptd-jsf-1.0-SNAPSHOT.war"
parent-domain="ptd-ear-1.0-SNAPSHOT.ear"
export-all="NON_EMPTY"
import-all="true"
parent-first="true">
In war file 2 -
<classloading xmlns="urn:jboss:classloading:1.0"
name="ptd-ws-1.0-SNAPSHOT.war"
domain="ptd-ws-1.0-SNAPSHOT.war"
parent-domain="ptd-ear-1.0-SNAPSHOT.ear"
export-all="NON_EMPTY"
import-all="true"
parent-first="true">
I was expecting the fact that I have parent-first set to true in the war files to mean that the classes in jars in the ear file would be loaded by the ear class loader not the war class loader but this is not the case.
I have done similar things in the websphere with no problems so I don't think my understanding is completely wrong.
Can anyone help me achieve what I want in JBoss 5.1.0.GA?
Thanks