21

次のプラグイン構成で「jetty:run」ゴールを呼び出しています。

<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>

プロジェクトが依存関係として slf4j を宣言しているにもかかわらず、Jetty は slf4j へのログ記録を拒否します。「-Dorg.eclipse.jetty.util.log.DEBUG=true」を JVM に渡すと、Jetty は大量のログを出力しますが、slf4j ではなく stderr に移動するようです。何か案は?

4

2 に答える 2

14

私自身の質問に答える:

  1. プラグインはプロジェクトの依存関係を認識しません。<dependencies>内に指定する必要があります<plugin>

  2. logback などの具体的な slf4j 実装を指定する必要があります。slf4j を指定するだけでは不十分です。

最終結果は次のようになります。

  <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>
于 2011-08-30T21:45:06.433 に答える
6

ギリの答えを少し拡張します。properties-maven-plugin を使用すると、コマンド ラインでシステム プロパティを指定する代わりに、システム プロパティを簡単に設定できます。logback と log4j の両方の例を示します。Gili の回答の jetty-maven-plugin 構成に加えて、このプラグイン ブロックを pom.xml に追加します。

ログバック:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>properties-maven-plugin</artifactId>
  <version>1.0-alpha-2</version>
  <executions>
    <execution>
      <goals>
        <goal>set-system-properties</goal>
      </goals>
      <configuration>
        <properties>
          <!-- makes jetty log the exception if it fails to initialize slf4j -->
          <property>
            <name>org.eclipse.jetty.util.log.IGNORED</name>
            <value>true</value>
          </property>
          <!-- Location of logback config -->
          <property>
            <name>logback.configurationFile</name>
            <value>/path/to/logback.xml</value>
          </property>
        </properties>
      </configuration>
    </execution>
  </executions>
</plugin>

Log4j:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>properties-maven-plugin</artifactId>
  <version>1.0-alpha-2</version>
  <executions>
    <execution>
      <goals>
        <goal>set-system-properties</goal>
      </goals>
      <configuration>
        <properties>
          <!-- makes jetty log the exception if it fails to initialize slf4j -->
          <property>
            <name>org.eclipse.jetty.util.log.IGNORED</name>
            <value>true</value>
          </property>
          <!-- this tells where the log4j configuration is -->
          <property>
            <name>log4j.configuration</name>
            <value>file:./src/main/resources/log4j.properties</value>
          </property>
          <!-- this can be uncommented to debug startup log4j itself,
               e.g. how it locates log4j.properties etc -->
          <!--
          <property>
            <name>log4j.debug</name>
            <value></value>
          </property>
          -->
        </properties>
      </configuration>
    </execution>
  </executions>
</plugin>

また、log4j の場合、当然のことながら、logback-classic の代わりに jetty-maven-plugin に次の依存関係を使用します。

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  ...
  <dependencies>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.6.4</version>
    </dependency>
  </dependencies>
</plugin>
于 2013-09-15T19:05:18.467 に答える