Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] embedded jetty, war context and slf4j/logback?

The biggest thing in your scenario is to know that a WebAppContext *must* (according to the servlet spec) follow a set of very strict classloader hierarchy rules.  You are constantly bumping your head into this low door frame without realizing it.

To simplify these rules (this is a gross oversimplification of the actual behavior).
Default java rules are to check the parent classloader first.
Default servlet rules are to check the webapps classloader first.
Server (implementation) classes are not to be exposed to webapp.

There are 2 approaches to resolving this.
  1. Tell the WebAppClassloader to always use the server side classloader of specific classes
        webapp.addSystemClass("org.slf4j.");
        webapp.addSystemClass("ch.qos.logback.");
  2. Tell the WebAppClassloader to always search the server side classloader before the WebAppClassloader
        webapp.setParentLoaderPriority(true);
Since you are an embedded user, you'll have to pick and choose what is most appropriate for you.
The addSystemClass() approach is best for maintaining this WebAppClassloader isolation but tweaking it slightly, especially useful if you have multiple WebApps in your environment that might have conflicting WEB-INF/lib contents.




--
Joakim Erdfelt <joakim@xxxxxxxxxxx>
Expert advice, services and support from from the Jetty & CometD experts


On Fri, Feb 28, 2014 at 2:15 AM, Kristian Rink <kawazu428@xxxxxxxxx> wrote:
Folks;

my setup: We run an embedded jetty in part of an application, and its only purpose is to expose an older war file. Both the war file and the application embedding jetty depend upon slf4j and logback, and in some ways it seems impossible to make this work. I have spent a couple of hours trying to make sure all slf4j maven dependencies are of the same version, same as I made sure the logback version is the same throughout the application - yet I can't get it to work and reproducibly end up with error messages fairly familiar from running "different" versions of slf4j modules somewhere... So to ask:

- Is there _any_ way in embedded jetty to make this sanely work?

- On another note: The jetty loads and exposes a war context. Why does the slf4j/logback configuration in the war context interfer with the rest of the application? Shouldn't this be independent of what happens "outside" the webapp?

TIA and all the best,
Kristian
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users


Back to the top