users@glassfish.java.net

Re: Application in ear does not load log4j.xml as expected

From: <glassfish_at_javadesktop.org>
Date: Wed, 11 Apr 2007 22:10:30 PDT

Thanks Siva, this give me more insight on my problem, however...

> > 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/b
> eade.html
>
> and hence classes/resources in the resource adapter
> would be loaded in
> precedence to classes in the ear.

You're right, I missed, thanks very much !!


> > 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=u
> sers&msgNo=590 help?

No, I've try to repackage, but doesn't help..

I guess the problem I have met is, connector classloader is the parent
of App Classloader.

Does application classloader (for one EAR) delegate using the standard approach
(ie, delegate to parent classloader first?)

If yes, and if connector classloader have loaded one class (LogFactory) when deploying
the RA module, subsequently, when loading of the EAR trigger a resolve of LogFactory.
The EAR will using the instance of LogFactory which are loaded by the connector classloader.

In the above scenario, the LogFactory will load Log4jAdapter, and then the log4j.xml
when loading the rar.

Though, the above stuff is simply guess of mine, but is it correct?
Actually, I know, the clasaloader chain is a complex topic~

IF this is cause of my problem, is it possible to enforce some control,
which class loaded by connector classloader is NOT visible to the Application (EAR)?

OR,

Can I package the rar inside the EAR.
If package RAR inside EAR is legal and supported,
then, both the EJB module and RAR module will live in the same Classloader
universe.. and my problem can also be solved...
Is it viable?

> > 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.

Originally, I put all jars in the ear (top level, not lib/, but I've now put the jars in lib/).
BTW, both are supported in Glassfish, am I right??

> > 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

Interesting :)

> > 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

Thanks again, I've read this before :)
But looks like it doesn't solve me problem here..


Best regards,
Zarick
[Message sent by forum member 'zarick' (zarick)]

http://forums.java.net/jive/thread.jspa?messageID=212015