Jetty
  1. Jetty
  2. JETTY-574

SLF4J classes not visible when added as dependencies to maven-jetty-plugin

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Not A Bug
    • Affects Version/s: 6.1.7, 6.1.8, 6.1.9, 7.0.0pre0, 7.0.0pre1
    • Fix Version/s: 6.1.7
    • Component/s: Maven
    • Labels:
      None
    • Number of attachments :
      1

      Description

      Adding SLF4J as a dependency to maven-jetty-plugin doesn't make it visible to the running webapp (NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder)
      It works fine with other libraries than SLF4J.

      Try mvn jetty:run with the attached project.

        Activity

        Hide
        Martin Strand added a comment -

        Oops, I mean the error is "NoClassDefFoundError: org/slf4j/LoggerFactory" since it's slf4j-api that isn't visible.

        Show
        Martin Strand added a comment - Oops, I mean the error is "NoClassDefFoundError: org/slf4j/LoggerFactory" since it's slf4j-api that isn't visible.
        Hide
        Igor E. Poteryaev added a comment -

        According to Jetty classloading architecture (see http://docs.codehaus.org/display/JETTY/Classloading),
        org.slf4j.* classes by default are included in so called ServerClasses and are hidden from webapp context classloaders.

        I think that you have two possibilities:

        1. Override default ServerClasses list excluding org.slf4j. from it. After it webapp context classloader will see slf4j classes from parent classloader.

        or

        2. Add slf4j dependencies not only to maven-plugin-jetty, but as dependency at top maven pom <dependencies> level . After it webapp context classloader will see slf4j classes from its own WEB-INF/lib/ directory.

        Show
        Igor E. Poteryaev added a comment - According to Jetty classloading architecture (see http://docs.codehaus.org/display/JETTY/Classloading ), org.slf4j.* classes by default are included in so called ServerClasses and are hidden from webapp context classloaders. I think that you have two possibilities: 1. Override default ServerClasses list excluding org.slf4j. from it. After it webapp context classloader will see slf4j classes from parent classloader. or 2. Add slf4j dependencies not only to maven-plugin-jetty, but as dependency at top maven pom <dependencies> level . After it webapp context classloader will see slf4j classes from its own WEB-INF/lib/ directory.
        Hide
        Martin Strand added a comment -

        Sorry for the false alarm, I didn't know Jetty was hiding certain classes.
        Your first suggestion works great, I added this to the plugin configuration and now everything's ok:

        <configuration>
        <webAppConfig>
        <contextPath>/test</contextPath>
        <serverClasses>
        <filter>-org.mortbay.jetty.plus.jaas.</filter>
        <filter>org.mortbay.jetty.</filter>
        </serverClasses>
        </webAppConfig>
        </configuration>

        Thanks!

        Show
        Martin Strand added a comment - Sorry for the false alarm, I didn't know Jetty was hiding certain classes. Your first suggestion works great, I added this to the plugin configuration and now everything's ok: <configuration> <webAppConfig> <contextPath>/test</contextPath> <serverClasses> <filter>-org.mortbay.jetty.plus.jaas.</filter> <filter>org.mortbay.jetty.</filter> </serverClasses> </webAppConfig> </configuration> Thanks!
        Hide
        Ken Dobson added a comment -

        Martin's comment was very helpful to me, but I found that further configuration is required if using jcl-over-slf4j because Jetty exposes the standard Commons Logging API to applications.

        Revised configuration:

        <webAppConfig>
        <contextPath>/test</contextPath>
        <serverClasses>
        <!-- Copied from WebAppContext with SLF4J removed -->
        <filter>-org.mortbay.jetty.plus.jaas.</filter>
        <filter>org.mortbay.jetty.</filter>
        </serverClasses>
        <systemClasses>
        <!-- Copied from WebAppContext with Commons Logging and Log4j removed -->
        <filter>java.</filter>
        <filter>javax.servlet</filter>
        <filter>javax.xml.</filter>
        <filter>org.mortbay.</filter>
        <filter>org.xml.</filter>
        <filter>org.w3c.</filter>
        </systemClasses>
        </webAppConfig>

        Apologies for bumping an old, closed bug, but I found this bug when Googling for the problem, and expect this information may be useful to others.

        Show
        Ken Dobson added a comment - Martin's comment was very helpful to me, but I found that further configuration is required if using jcl-over-slf4j because Jetty exposes the standard Commons Logging API to applications. Revised configuration: <webAppConfig> <contextPath>/test</contextPath> <serverClasses> <!-- Copied from WebAppContext with SLF4J removed --> <filter>-org.mortbay.jetty.plus.jaas.</filter> <filter>org.mortbay.jetty.</filter> </serverClasses> <systemClasses> <!-- Copied from WebAppContext with Commons Logging and Log4j removed --> <filter>java.</filter> <filter>javax.servlet</filter> <filter>javax.xml.</filter> <filter>org.mortbay.</filter> <filter>org.xml.</filter> <filter>org.w3c.</filter> </systemClasses> </webAppConfig> Apologies for bumping an old, closed bug, but I found this bug when Googling for the problem, and expect this information may be useful to others.
        Hide
        Fabio Marinelli added a comment -

        In reply to Ken comment, there's a missing dot on javax.servlet

        This is the working configuration.

        <webAppConfig>
        <contextPath>/test</contextPath>
        <serverClasses>
        <!-- Copied from WebAppContext with SLF4J removed -->
        <filter>-org.mortbay.jetty.plus.jaas.</filter>
        <filter>org.mortbay.jetty.</filter>
        </serverClasses>
        <systemClasses>
        <!-- Copied from WebAppContext with Commons Logging and Log4j removed -->
        <filter>java.</filter>
        <filter>javax.servlet.</filter>
        <filter>javax.xml.</filter>
        <filter>org.mortbay.</filter>
        <filter>org.xml.</filter>
        <filter>org.w3c.</filter>
        </systemClasses>
        </webAppConfig>

        Bye and sorry for posting again on this issue.

        Show
        Fabio Marinelli added a comment - In reply to Ken comment, there's a missing dot on javax.servlet This is the working configuration. <webAppConfig> <contextPath>/test</contextPath> <serverClasses> <!-- Copied from WebAppContext with SLF4J removed --> <filter>-org.mortbay.jetty.plus.jaas.</filter> <filter>org.mortbay.jetty.</filter> </serverClasses> <systemClasses> <!-- Copied from WebAppContext with Commons Logging and Log4j removed --> <filter>java.</filter> <filter>javax.servlet.</filter> <filter>javax.xml.</filter> <filter>org.mortbay.</filter> <filter>org.xml.</filter> <filter>org.w3c.</filter> </systemClasses> </webAppConfig> Bye and sorry for posting again on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Martin Strand
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: