felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karl Pauls <karlpa...@gmail.com>
Subject Re: pax-logging / log4 / Felix embedded in a Web App
Date Tue, 27 Nov 2012 10:37:43 GMT
Equinox is doing some magic by default which is effectively setting the
context classloader to load classes from the current bundle. This may or
may not be what you want (in this specific case it is) -- hence, we don't
do that in felix and you have to do that yourself. In any case, the spec is
mum on the issue.

regards,

Karl


On Tue, Nov 27, 2012 at 11:33 AM, Bengt Rodehav <bengt@rodehav.com> wrote:

> Thanks for the explanation. One question though:
>
> The problem I had (log4j classes were present in jar:s in the Windows
> CLASSPATH which caused them to found by the application classloader)
> disappeared  when using Equinox instead of Felix. What is Felix doing
> different than Equinox? Is Equinox by default setting the CCL to null?
>
> /Bengt
>
>
> 2012/11/27 Karl Pauls <karlpauls@gmail.com>
>
> > The problem is the context classloader. You have to make sure you set the
> > context classloader to null when starting felix and when calling into
> felix
> > from the outside.
> >
> > The thing is, threads inherit the current context class loader.
> > Furthermore, the context classloader gets set by the servlet container
> when
> > the bridge servlet is called.
> >
> > The problem is that log4j is stupid and assumes that it should use the
> > context classloader first to try to find classes. That isn't going to
> work
> > when log4j is comming from a bundle -- hence, you have two options:
> >
> > 1. Set the context classloader to null while creating the framework
> > instance and starting it _and_ set it to null when calling into the
> > framework from the outside (_make sure_ to _set it back_ when you
> return).
> >
> > 2. Don't provide log4j from a bundle but make it available via the system
> > bundle (i.e., use a version that you have outside and delegate it down).
> >
> > regards,
> >
> > Karl
> >
> >
> > On Tue, Nov 27, 2012 at 8:26 AM, Bengt Rodehav <bengt@rodehav.com>
> wrote:
> >
> > > Hello Charles,
> > >
> > > I recently had a similar problem that I brought up on the Karaf user
> > list:
> > >
> > >
> > >
> >
> http://mail-archives.apache.org/mod_mbox/karaf-user/201211.mbox/%3CCAJ0TPG%2BERzf6Q709cndh-YqfP_HQq%3DVk6iA4ZQfEtZE7tJPWUw%40mail.gmail.com%3E
> > >
> > > Although my problem was that the application classloader had already
> > loaded
> > > some log4j classes due to the CLASSPATH environment variable on
> Windows,
> > I
> > > noted that everything worked fine using Equinox instead of Felix.
> > >
> > > Apparently Equinox does some tricks when it comes to hiding already
> > loaded
> > > classes. Maybe Felix developers can take a look at what Equinox is
> doing
> > > and perhaps do something similar in Felix thus making Felix more
> > resilient
> > > to "polluted" classloaders.
> > >
> > > /Bengt
> > >
> > >
> > >
> > > 2010/11/18 Charles Moulliard <cmoulliard@gmail.com>
> > >
> > > > Hi,
> > > >
> > > > Some months ago, an interesting question has been drawn about the
> > > > classloading issue of log4j class when we use pax-logging bundle
> within
> > > > Felix embedded in a web application.
> > > >
> > > > http://www.mail-archive.com/**dev@felix.apache.org/msg04908.**html<
> > > http://www.mail-archive.com/dev@felix.apache.org/msg04908.html>
> > > >
> > > > I'm faced to the same issue when I would like to use Apache Karaf
> (top
> > > > level container of Apache Felix) deployed as a WAR.
> > > >
> > > > Does anybody has find a trick to solve the classloading issue ?
> > > >
> > > > INFO: locking
> > > > 2010-11-18 18:08:36.667:INFO::Started SelectChannelConnector@0.0.0.
> **
> > > > 0:8080 <http://SelectChannelConnector@0.0.0.0:8080>
> > > > [INFO] Started Jetty Server
> > > > [INFO] Starting scanner at interval of 10 seconds.
> > > > log4j:ERROR A "org.apache.log4j.**ConsoleAppender" object is not
> > > > assignable to a "org.apache.log4j.Appender" variable.
> > > > log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
> > > > log4j:ERROR [4.0] whereas object of type
> > > > log4j:ERROR "org.apache.log4j.**ConsoleAppender" was loaded by
> > > > [ContextLoader@ServiceMix Embedded Example].
> > > >
> > > >
> > > > Regards,
> > > >
> > > > Charles M.
> > > > Apache Camel, ServiceMix & Karaf committer
> > > >
> > >
> >
> >
> >
> > --
> > Karl Pauls
> > karlpauls@gmail.com
> > http://twitter.com/karlpauls
> > http://www.linkedin.com/in/karlpauls
> > https://profiles.google.com/karlpauls
> >
>



-- 
Karl Pauls
karlpauls@gmail.com
http://twitter.com/karlpauls
http://www.linkedin.com/in/karlpauls
https://profiles.google.com/karlpauls

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message