Configure logging for Jetty's maven plugin?

Gili picture Gili · Aug 24, 2011 · Viewed 14.8k times · Source

I'm invoking the "jetty:run" goal with the following plugin configuration:

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>7.4.4.v20110707</version>
  <configuration>
    <scanIntervalSeconds>5</scanIntervalSeconds>
    <connectors>
      <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <port>80</port>
      </connector>
    </connectors>        
  </configuration>
</plugin>

Jetty refuses to log anything to slf4j in spite of the fact that my project declares slf4j as a dependency. If I pass "-Dorg.eclipse.jetty.util.log.DEBUG=true" to the JVM, Jetty outputs tons of logs but they seem to go to stderr instead of to slf4j. Any ideas?

Answer

Gili picture Gili · Aug 30, 2011

Answering my own question:

  1. Plugins don't see the project dependencies. You need to specify <dependencies> inside the <plugin>.

  2. You need to specify a concrete slf4j implementation, such as logback. Specifying slf4j is not enough.

The end-result should look something like this:

  <plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>7.4.4.v20110707</version>
    <configuration>
      <scanIntervalSeconds>5</scanIntervalSeconds>
      <connectors>
        <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
          <port>80</port>
        </connector>
      </connectors>        
    </configuration>
    <dependencies>
      <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>0.9.29</version>
      </dependency>
    </dependencies>
  </plugin>