You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Charles Moulliard <cm...@gmail.com> on 2010/10/21 13:50:04 UTC

How to avoid that log4j classes are loaded twice

Hi,

When Karaf is deployed as a WAR in Jetty or Tomcat, log4j classes are 
loaded twice and of course Karaf is not able to report trace in 
servicemix.log file.

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].
log4j:ERROR Could not instantiate appender named "A1".
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].

Does anybody has an idea to avoid that ?

Regards,

Charles

Re: How to avoid that log4j classes are loaded twice

Posted by Charles Moulliard <cm...@gmail.com>.
That means that we must create a specific profile in Maven when we 
generate SMX4 as a WAR to avoid to load them twice.

On 21/10/10 14:27, Jean-Baptiste Onofré wrote:
> It's linked to the JEE/WAR classloading management.
>
> By default, Tomcat has a hierarchical classloader: Bootstrap, System, 
> Common, One Classloader per Webapp, in this order.
>
> As log4j is already loaded by the Bootstrap classloader, you have a 
> "collision".
> A possible workaround is to remove the Karaf log4j to use the 
> Bootstrap one.
>
> Regards
> JB
>
> On 10/21/2010 01:50 PM, Charles Moulliard wrote:
>> Hi,
>>
>> When Karaf is deployed as a WAR in Jetty or Tomcat, log4j classes are
>> loaded twice and of course Karaf is not able to report trace in
>> servicemix.log file.
>>
>> 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].
>> log4j:ERROR Could not instantiate appender named "A1".
>> 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].
>>
>> Does anybody has an idea to avoid that ?
>>
>> Regards,
>>
>> Charles

Re: How to avoid that log4j classes are loaded twice

Posted by Guillaume Nodet <gn...@gmail.com>.
That would not work (or it might, but I doubt it), as karaf uses pax-logging
which has some modified versions of the log4j classes in order to make them
work nicely in OSGi.

On Thu, Oct 21, 2010 at 14:27, Jean-Baptiste Onofré <jb...@nanthrax.net> wrote:

> It's linked to the JEE/WAR classloading management.
>
> By default, Tomcat has a hierarchical classloader: Bootstrap, System,
> Common, One Classloader per Webapp, in this order.
>
> As log4j is already loaded by the Bootstrap classloader, you have a
> "collision".
> A possible workaround is to remove the Karaf log4j to use the Bootstrap
> one.
>
> Regards
> JB
>
>
> On 10/21/2010 01:50 PM, Charles Moulliard wrote:
>
>> Hi,
>>
>> When Karaf is deployed as a WAR in Jetty or Tomcat, log4j classes are
>> loaded twice and of course Karaf is not able to report trace in
>> servicemix.log file.
>>
>> 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].
>> log4j:ERROR Could not instantiate appender named "A1".
>> 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].
>>
>> Does anybody has an idea to avoid that ?
>>
>> Regards,
>>
>> Charles
>>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com

Re: How to avoid that log4j classes are loaded twice

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
It's linked to the JEE/WAR classloading management.

By default, Tomcat has a hierarchical classloader: Bootstrap, System, 
Common, One Classloader per Webapp, in this order.

As log4j is already loaded by the Bootstrap classloader, you have a 
"collision".
A possible workaround is to remove the Karaf log4j to use the Bootstrap one.

Regards
JB

On 10/21/2010 01:50 PM, Charles Moulliard wrote:
> Hi,
>
> When Karaf is deployed as a WAR in Jetty or Tomcat, log4j classes are
> loaded twice and of course Karaf is not able to report trace in
> servicemix.log file.
>
> 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].
> log4j:ERROR Could not instantiate appender named "A1".
> 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].
>
> Does anybody has an idea to avoid that ?
>
> Regards,
>
> Charles

Re: How to avoid that log4j classes are loaded twice

Posted by Charles Moulliard <cm...@gmail.com>.
This is the same between equinox or felix.

On 21/10/10 14:12, Guillaume Nodet wrote:
> That's where the JEE fun begins.  I suppose you need to configure you 
> JEE web server to not make the log4j classes available to the war.  I 
> don't think there's a standard way of doing that though ...
> Is the behavior the same wether you use Felix or Equinox ?
>
> On Thu, Oct 21, 2010 at 13:50, Charles Moulliard <cmoulliard@gmail.com 
> <ma...@gmail.com>> wrote:
>
>     Hi,
>
>     When Karaf is deployed as a WAR in Jetty or Tomcat, log4j classes
>     are loaded twice and of course Karaf is not able to report trace
>     in servicemix.log file.
>
>     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].
>     log4j:ERROR Could not instantiate appender named "A1".
>     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].
>
>     Does anybody has an idea to avoid that ?
>
>     Regards,
>
>     Charles
>
>
>
>
> -- 
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> ------------------------
> Open Source SOA
> http://fusesource.com
>
>

Re: How to avoid that log4j classes are loaded twice

Posted by Guillaume Nodet <gn...@gmail.com>.
That's where the JEE fun begins.  I suppose you need to configure you JEE
web server to not make the log4j classes available to the war.  I don't
think there's a standard way of doing that though ...
Is the behavior the same wether you use Felix or Equinox ?

On Thu, Oct 21, 2010 at 13:50, Charles Moulliard <cm...@gmail.com>wrote:

> Hi,
>
> When Karaf is deployed as a WAR in Jetty or Tomcat, log4j classes are
> loaded twice and of course Karaf is not able to report trace in
> servicemix.log file.
>
> 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].
> log4j:ERROR Could not instantiate appender named "A1".
> 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].
>
> Does anybody has an idea to avoid that ?
>
> Regards,
>
> Charles
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com