user3125878
user3125878

Reputation: 35

maven fails to find slf4j rollingfileappender

I'm having a problem where maven is not finding the slf4j classes when running JUnit tests:

22:20:05,412 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
22:20:05,412 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [file:/home/ram/src/2dd/java/dd2/target/test-classes/logback-test.xml]
22:20:05,526 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.RollingFileAppender]
22:20:05,527 |-ERROR in ch.qos.logback.core.joran.action.AppenderAction - Could not create an Appender of type [ch.qos.logback.core.RollingFileAppender]. ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type ch.qos.logback.core.RollingFileAppender

However, the slf4j jar files are being added to the classpath:

[DEBUG] test classpath classpath:
[DEBUG]   /home/ram/src/2dd/java/dd2/target/test-classes
[DEBUG]   /home/ram/src/2dd/java/dd2/target/classes
[DEBUG]   /home/ram/.m2/repository/junit/junit/4.11/junit-4.11.jar
[DEBUG]   /home/ram/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
[DEBUG]   /home/ram/.m2/repository/com/fallabs/kyotocabinet-java/1.24/kyotocabinet-java-1.24.jar
[DEBUG]   /home/ram/.m2/repository/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar
[DEBUG]   /home/ram/.m2/repository/ch/qos/logback/logback-core/1.0.13/logback-core-1.0.13.jar
[DEBUG]   /home/ram/.m2/repository/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar
[DEBUG] provider classpath classpath:
[DEBUG]   /home/ram/.m2/repository/org/apache/maven/surefire/surefire-junit4/2.12.4/surefire-junit4-2.12.4.jar
[DEBUG]   /home/ram/.m2/repository/org/apache/maven/surefire/surefire-api/2.12.4/surefire-api-2.12.4.jar

My logback-test.xml file closely follows the example at: http://logback.qos.ch/manual/appenders.html

<appender name="FILE" class="ch.qos.logback.core.RollingFileAppender">  
  <file>gen-test.log</file>
  <rollingPolicy
      class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
    <fileNamePattern>gen-test.%i.log</fileNamePattern>
    <minIndex>1</minIndex>
    <maxIndex>3</maxIndex>
  </rollingPolicy>

  <triggeringPolicy
      class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
    <maxFileSize>2MB</maxFileSize>
  </triggeringPolicy>

  <encoder>
    <pattern>%date %level [%thread] %logger{36} [%file:%line] - %msg%n
   </pattern>
  </encoder> 
</appender>

<root level="debug">  
  <appender-ref ref="FILE" />  
</root>  

My pom.xml has these relevant parts:

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.11</version>
  <scope>test</scope>
</dependency>
<dependency>  <!-- pulls in slf4j -->
  <groupId>ch.qos.logback</groupId>
  <artifactId>logback-classic</artifactId>
  <version>1.0.13</version>
</dependency>
....
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
      <verbose>true</verbose>
      <fork>true</fork>
      <!-- <executable>${JAVA_HOME}/bin/javac</executable> -->
      <compilerVersion>1.7</compilerVersion>
      <source>1.7</source>
      <target>1.7</target>
      <compilerArgs>
        <!-- <arg>-Xmaxerrs=100</arg> -->
        <arg>-Xlint</arg>
      </compilerArgs>
    </configuration>
  </plugin>

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.16</version>
  <configuration>
    <forkCount>0</forkCount>
    <!-- <forkMode>pertest</forkMode> -->
    <argLine>-Xms128m -Xmx1g</argLine>
    <argLine>-Djava.library.path=.:/usr/local/lib</argLine>
    <testFailureIgnore>false</testFailureIgnore> 
    <skip>false</skip> 
    <!--
    <useSystemClassLoader>true</useSystemClassLoader>
    <useManifestOnlyJar>false</useManifestOnlyJar>
    -->
  </configuration>
</plugin>

Appreciate any help, thanks.

Upvotes: 3

Views: 5731

Answers (1)

MystyxMac
MystyxMac

Reputation: 1552

It seems your FILE appender has the wrong class. I use

ch.qos.logback.core.rolling.RollingFileAppender

You miss the .rolling in the path.

Upvotes: 24

Related Questions