users@glassfish.java.net

Re: Application in ear does not load log4j.xml as expected (classloading issue)

From: Sivakumar Thyagarajan <Sivakumar.Thyagarajan_at_Sun.COM>
Date: Wed, 11 Apr 2007 16:09:39 +0530

Hi Zarick

Responses inline.

Thanks
--Siva.

glassfish_at_javadesktop.org wrote:
> Hi,
>
> I getting a strange, classloader related problem.
>
> My deployment consists of one RAR and one EAR
> - RAR is genericjmsra + Activemq. (I put all deps into the rar, including log4j, jcl)
> - EAR is our own application.
> Two deployment both include commons-logging + log4j.
>
> When deploying the ear, log4j.xml in .rar is used, rather than the one
> included in the ear (I include log4j.xml in the myejb.jar, which included in the ear)
>
> So, as I can see, the classloader universe is shared for both the ear and the rar,
> Am I right??
>

The standalone resource adapter [RAR] is loaded by the connector
classloader as shown in fig2-1 at
https://glassfish.dev.java.net/nonav/javaee5/docs/DG/beade.html

and hence classes/resources in the resource adapter would be loaded in
precedence to classes in the ear.

> If I want to enclose my application (ear) specific log4j.xml in the .ear, what can I do.

Does the response at
https://glassfish.dev.java.net/servlets/ReadMsg?list=users&msgNo=590 help?

> I think that, putting logging config (which are specific with my apps) into the RAR
> is not a sane approach.

Yes.

>
> Also, I've read the developer guide which talks about classloader universe.
> Is it true that, if I deploy an EAR, all the lib inside is loaded with one AppClassLoader?

Are you referring to the libraries in your EAR's library-directory? If yes,
then yes these libraries are loaded by one classloader, the application's
classloader.

> How about RAR, it haven't mentioned about RAR?
>
The classes of a standalone resource adapter is loaded by "a" classloader
instance in the connector classloader. The Connector ClassLoader is not a
conventional JAR or URL ClassLoader but is a chain of classloader and that
is how we achieve loading and unloading of multiple standalone resource
adapter classloaders while still maintaining isolation between individual
standalone resource adapters

> Finally, if my rar consists of a few dependency, should I package all the dep of the RAR
> into one unit.
> Just put all dep into the rar?

Yes this should work. If the dependencies are also used by multiple
applications in your domain and not only by the resource adapter, you could
consider using the approaches outlined in the question "How do I control
visibility scope of my libraries" in
http://blogs.sun.com/sivakumart/entry/classloaders_in_glassfish_an_attempt

Hope this helps

Thanks
--Siva.
http://blogs.sun.com/sivakumart

>
> Thanks in advance
> Zarick
> [Message sent by forum member 'zarick' (zarick)]
>
> http://forums.java.net/jive/thread.jspa?messageID=211828
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>