views:

808

answers:

2

I have a few separate application projects (EARs) with multiple EJBs that I want to deploy to the same JBoss server. Now, some of the projects may have the same EJBs, but different versions. In similar circumstances, some projects may use different versions of the same "ordinary" classes (i.e. classes loaded within VM, without JNDI lookup).

With OC4J, this seems not to have been a problem, but now with JBoss, I get the impression that everything resides in the same "name space" (or class loader perhaps). Am I correct in this assumption?

Basically, what I want to do (or ensure) are two things:

  • From a client that does a JNDI-lookup of an EJB, I want to be able to indicate which application it resides in, so that the correct version of the EJB is returned.

  • From within an EJB, when instantiating a class, I want to ensure that the class is the one deployed with the same application (EAR) as the EJB was.

I think I read that you could configure some "isolation" properties for EJBs, am I guessing correctly in that might would solve my second point?

+2  A: 

You're correct that classes from different EAR's reside in the same "space". JBoss uses by default a flat classloader hierarchy, meaning that all classes (except for WAR packaged ones) are loaded by the same classloader. With the introduction of JBoss 5 there's a new standard profile that strictly follows the JEE rules and thus supports isolated classloading. Older JBoss versions also support this behavior through the callByValue and isolate properties in the deployer configuraion.

R. Kettelerij
+3  A: 

JBoss's default behaviour is to use a flat classloader. This reduces the footprint, but as you've found, it makes deploying multiple applications troublesome.

Thankfully, the fix is easy. In the ear-deployer.xml file in the deploy directory, make sure the following parameter is set:

<attribute name="Isolated">true</attribute>

This will give each deployed EAR its own classloader space. It will still be able to access stuff from the JBoss lib directory, but the deployed EARs will be invisible to each other.

skaffman
Thanks for your informative reply! I ended up choosing Kettelerijs reply as the accepted answer, but your reply was very useful as well.
Brummo