users@glassfish.java.net

Re: Classloader Hierarchy in Glassfish using deployed Resource adapters

From: Jagadish Prasath Ramu <jagadish.ramu_at_oracle.com>
Date: Mon, 23 Jan 2012 22:25:37 +0530

Hi :

On Mon, 2012-01-23 at 10:54 -0200, Gustavo Henrique Orair wrote:
> I'm having problems with classloading when using Glassfish ResourceAdapters.
> By deploying rar, their libraries seem to take precedence to both
> Glassfish libraries and application libraries itself.
The class-loader hierarchy in GlassFish is as follows :
application-CL -> app-lib-CL -> connector-CL (RAR) ->common-CL ->
extension-CL -> Bootstrap-CL

http://docs.oracle.com/cd/E18930_01/html/821-2418/beadf.html

So, if you have copied any library to GF_HOME/lib or
GF_HOME/domains/<domain>/lib directory, they will take precedence over
RAR's classes/libraries.

Similarly, the RAR classes/libraries will take precendence over
application classes/libraries.
>
> When deploying jackrabbit JCA with global classloading , this resulted
> in a conflict in the ejb-timer-service that used the derby library
> because there was a different derby version inside the jackrabbit.rar.
I assume, this is a different issue than :
http://java.net/jira/browse/GLASSFISH-18082

> In addition, my application uses the Logback and has the file
> logback.xml with the settings of the Logging system. But it seems that
> the classloader system first the logback.xml inside a library jar
> (jackrabbit-jca.jar) within the resource adapter jackrabbit-jca.rar.
> So, it used the logback.xml shipped within jackrabbit-jca.rar instead
> of my own configuration.
That depends on how the logback.xml resource is being loaded by the
application.
Please provide a test-case to see what's going on.
>
> I would like to understand better the priority rules of loading when
> using Resource Adapters.
Above class-loader hierarchy should help to understand the order in
which the delegation will happen.
>
> This problem results in several other classloading problems such as
> commons-io inside the jackrabbit-jca.rar is at version 1.4 and my
> application uses version 2.0.1.
>
> Is there any way to "isolate" the Rar libraries for use only in
> classes inside this rar? What's the best approach to avoid all these
> conflicts?
If the application does not use the RAR, then by default
(connector-class-loading policy is "derived"), the RARs classes will not
be seen. If the application uses the RAR, then RAR classes will take
precedence. AFAIK, right approach would be to make sure that both the
RAR and the application use common (same version) libraries. Other
option is to copy the library that you want to be used to GF_HOME/lib
directory so that both application and RAR will use the libraries in
GF_HOME/lib.

Thanks,
-Jagadish
>
> If anyone has faced these problems in a similar environment, what is
> the recommended way to configure this environment?
>
> ---------------------------------------------------------------------------------------------------------------------
> Gustavo Henrique Orair
> ------------------------------------------------------------------------------------------------------------------