Estendere la risposta di Gili un po '; usando le proprietà-maven-plugin è un modo conveniente per impostare le proprietà di sistema invece di doverle specificare sulla riga di comando. Fornisco esempi sia per il logback che per log4j. Aggiungi questo blocco plugin al tuo pom.xml in aggiunta alla configurazione del jetty-maven-plugin nella risposta di Gili.
Logback:
<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>
Anche per log4j, utilizzare naturalmente la seguente dipendenza per il pontile-maven-plugin invece di logback-classico:
<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>
fonte
2013-09-15 19:05:18
Nota, per configurare la registrazione basta lasciare esperto di sapere dove il file di configurazione è: mvn verificare -Dlogback.configurationFile =/path/to/logback.xml – Mike
C'è un aggiornamento per la versione 9? Non vedo alcun log da Jetty quando utilizzo questa configurazione. – user64141
@ user64141 Non sono a conoscenza di eventuali modifiche. Detto questo, non uso più il plugin Maven Jetty. Ora invoco Jetty da una normale classe Java. – Gili