views:

40

answers:

2

To summarize the issue I'm encountering, I have an EJB which uses version A of a library (let's call it dep-vA.jar). dep-vA.jar is packaged in the root of the EJB's jar file. The domain lib folder in the application server contains version B of the same library (let's call it dep-vB.jar). When calling the EJB, I get an error due to dep-vB.jar file being loaded rather than dep-vA.jar.

I guess the first part of this question is, does Sun One Application Server v9.1 isolate EJBs from each other? I was under the impression that it does. But it seems like another application loaded dep-vB.jar and this EJB is directly using it without loading its own.

The second question is, if the app server does isolate EJBs, does it load dependencies from the EJB's jar file before looking in the application server's lib folders? I was under the impression that this is also true, but maybe not...

Is anyone familiar enough with Sun application servers to explain why dep-vB.jar is being loaded rather than dep-vA.jar? Is there any way to get it to load dep-vA.jar without changing what's in the application server's lib folders? (I would hesitate to do anything that might affect other applications on the server)

Thanks.

A: 

I haven't used that particular server, but I do know that in WebSphere, there is an option to use PARENT_FIRST or PARENT_LAST classloading. You would be looking for an equivalent of PARENT_LAST where the classes are loaded from the EAR first before going up to the server.

I would assume that such a configuration is possible in any app server, as you should always be able to enforce your application specific jars to be loaded over any others.

Robin
In JBoss there are similar classloading controls on EAR's and WAR's.
Peter Tillemans
I've seen this option for web applications, but I can't find an equivalent for EJBs.
jthg
At least in WebSphere, the EJB component does not have it's own classloader (the WAR does, not that it matters in your case). It uses the EAR classloader so that setting would exist at that level.
Robin
+1  A: 

I guess the first part of this question is, does Sun One Application Server v9.1 isolate EJBs from each other? I was under the impression that it does. But it seems like another application loaded dep-vB.jar and this EJB is directly using it without loading its own.

According to Sahoo (which is a GlassFish developer), the Java EE spec does not mandate class loading isolation among modules of a single ear so the behavior can be different from one app server to another. With Sun ONE, my understanding of the documentation is that EJB-JARs are isolated.

The second question is, if the app server does isolate EJBs, does it load dependencies from the EJB's jar file before looking in the application server's lib folders? I was under the impression that this is also true, but maybe not...

It's a parent-first strategy (and to my knowledge, Sun ONE allows to change the delegating mode for webapps only).

That being said, what happens if you list dep-vA.jar in the Class-Path entry of the MANIFEST.MF of the EJB-JAR?

See also

Pascal Thivent
Thanks! Rereading the docs (more carefully), I guess this is exactly what the Sun docs say. Although I think it's a bit ambiguous on whether the EJB class loader delegates to the parent and whether that can be changed. I'll try the manifest class path idea tomorrow. I should mention though that if I do remove dep-vB.jar from the domain lib folder, the app server does correctly find and load dep-vA.jar.
jthg
You meant adding "Class-Path: dep-vA.jar" to the manifest right? I tried it and it doesn't make a difference.
jthg
@jthg: Yes, this is what I meant. To be honest, I'm not sure this changed anything (since `dep-vA.jar` is not in the EAR) and I'm not expecting the result to be different anyway (I just wanted to get confirmation of my understanding).
Pascal Thivent