Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Jetty + Slf4j

On Tue, Dec 8, 2009 at 11:32 AM, Julio Viegas
<julioviegas@xxxxxxxxxxxxxxx> wrote:
> Hello Hugues,
>
>   I use slf4 with log4j adapter libs inside my app and never ran into
> those kinds of problems. I'm using 6.1.14 and tested with 6.1.19 which
> also is fine. Weird...
Ok, it might be a different situation then.
>
>   I use Jetty through the start.jar support and not the pre-packaged scripts.
start.jart still reads the configuration files and creates the
server's classloader with the shared libraries in lib/ext etc:
http://docs.codehaus.org/display/JETTY/A+look+at+the+start.jar+mechanism
(my apologies if you have seen this)

So even though you are not using the pre-configured script it is still
picking up the jars located inside /usr/share/java/

Now inside your webapp something is calling the slf4j API directly:
not through the log4j logger.
So here is what happens in the 2 situation:
#1- you have slf4j inside the webapp: slf4j will find the 2
implementations: one in the shared lib and the other in the webapp.
jetty prevents the webapp to access org.slf4j.* located outside of the
webapp but it does not prevent the webapp to access classes inside
org.slf4j.impl that are in the shared libraries.
hence the warning.

#2- slf4j-api.jar is not in your webapp. Something is doing inside
your application a call to org.slf4j.LoggerFactory.
jetty refuses to give you access to the shared slf4j-api that is
inside the server classloader (see
http://www.mortbay.org/xref/org/mortbay/jetty/webapp/WebAppContext.html#98)
crash.
Maybe one of your dependencies changed: before you used to do all the
logging calls via log4j and now there is a direct call to slf4j?

Until we found this workaround, we were just avoiding the direct calls
to slf4j APIs.

Maybe we missed something obvious and there is somethign a lot simpler
to do. But it does sound like you have the same problem.

Best,
Hugues.
>
> Rgrds,
> JV -- julioviegas.com
>
>
> On Tue, Dec 8, 2009 at 17:12, Hugues Malphettes <hmalphettes@xxxxxxxxxxx> wrote:
>> Hi Julio,
>> We faced this issue with jetty6 with the standard distribution.
>> We chose to do this:
>> 1- remove *slf4j*, commons-logging, log4j jars from the webapp.
>> 2- add a jetty6-web.xml inside the WEB-INF of our web-application that
>> contains this xml:
>> <?xml version="1.0"  encoding="ISO-8859-1"?>
>> <Configure class="org.mortbay.jetty.webapp.WebAppContext">
>>    <Set name="serverClasses">
>>        <Array type="java.lang.String">
>>            <Item>-org.mortbay.jetty.plus.jaas.</Item>
>>            <Item>org.mortbay.jetty.</Item>
>>        </Array>
>>    </Set>
>> </Configure>
>>
>> Jetty6 does something special with the webapp classloader that
>> prevents a web-application to access the org.slf4j.* classes that are
>> provided by the server's classloader. I have not really understood the
>> reason for this; although I am guessing it is to support some
>> isolation of the logging for each webapp.
>> Adding this jetty6-web.xml will basically let your webapp access the
>> shared slf4j. slf4j will locate the other *slf4j* jars in the server's
>> classes loader.
>>
>>
>> This setup will enforce "centralized" logging in jetty6:
>> the configuration of the logging is done in one single place:
>> ${jetty.home}/resources/log4j.properties (or logback.xml)
>> for all web-applications.
>> You should add log4j.jar inside the shared libraries (or
>> logback-core+logback-classic). In the standard distribution of jetty6
>> that would be inside ${jetty.home}/lib/ext.
>> I am not sure where it is in the debian distribution.
>>
>>
>> Jetty7 will support configuration of centralized logging as an option
>> and I believe will not have this kind of difficult issue anymore.
>>
>> I hope this helps,
>> Hugues.
>>
>> On Tue, Dec 8, 2009 at 10:39 AM, Julio Viegas
>> <julioviegas@xxxxxxxxxxxxxxx> wrote:
>>> Hello Diego,
>>>
>>>   How are you starting Jetty? I mean, can you check your Jetty's JVM
>>> classpath setting?
>>>
>>>   I suspect "jar:file:/usr/share/java/slf4j-simple-1.5.8.jar" is
>>> inside your $CLASSPATH or something like that...
>>>
>>> Rgrds,
>>> JV -- julioviegas.com
>>>
>>> On Tue, Dec 8, 2009 at 16:26, Diego Plentz <diego@xxxxxxxxxx> wrote:
>>>> Hey guys,
>>>> I'm using jetty 6.1.x installed through apt-get in a Ubuntu box. When I
>>>> deploy my application, I have a problem with slf4j. If I deploy my war with
>>>> slf4j-log4j12-1.5.8.jar, I have this message:
>>>> SLF4J: Class path contains multiple SLF4J bindings.
>>>> SLF4J: Found binding in
>>>> [jar:file:/usr/share/java/slf4j-simple-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
>>>> SLF4J: Found binding in
>>>> [jar:file:/var/cache/jetty/Jetty_0_0_0_0_8080_suporte_promotor.war___suporte.promotoronline.com.br_ivstzq/webapp/WEB-INF/lib/slf4j-log4j12-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
>>>> SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an
>>>> explanation.
>>>> But, if I remove the jar from the war file, I have a NoClassDefFoundError:
>>>> Caused by: java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
>>>> at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:223)
>>>> at org.slf4j.LoggerFactory.bind(LoggerFactory.java:120)
>>>> at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
>>>> at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)
>>>> ....
>>>> What is the correct behavior?
>>>> --
>>>> http://plentz.org
>>>> http://twitter.com/plentz
>>>>
>>>> _______________________________________________
>>>> jetty-users mailing list
>>>> jetty-users@xxxxxxxxxxx
>>>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>>>
>>>>
>>> _______________________________________________
>>> jetty-users mailing list
>>> jetty-users@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>>
>> _______________________________________________
>> jetty-users mailing list
>> jetty-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>
> _______________________________________________
> jetty-users mailing list
> jetty-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>


Back to the top