views:

23

answers:

1

Hi all,

I'm trying to use jdbcdslog or log4jdbc with maven2. - I want to log all SQL that is executed by mvn-sql.

I installed slf4j-api (1.6.1), slf4j-log4j12 (1.6.1) and jdbcdslog (1.0.5) Jars to my local maven2-repo and configured in my pom.xml the following:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>sql-maven-plugin</artifactId>
  <version>1.3</version>
  <dependencies>
    <dependency>
      <groupId>jdbcdslog</groupId>
      <artifactId>jdbcdslog</artifactId>
      <version>1.0.5</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.6.1</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.6.1</version>
    </dependency>
    <dependency>
      <groupId>com.oracle</groupId>
      <artifactId>ojdbc14</artifactId>
      <version>9.0.2.0.0</version>
    </dependency>
  </dependencies>

  <configuration>
    <driver>org.jdbcdslog.DriverLoggingProxy</driver>
  </configuration>

  <executions>
    <execution>
       ...
      <configuration>    <url>jdbc:jdbcdslog:oracle:thin:@myurl.com:1521:TEST;targetDriver=oracle.jdbc.driver.OracleDriver</url>
      ...
      </configuration>
    </execution>                    
  </executions>
</plugin>

Executing this leads to:

java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at org.jdbcdslog.DriverLoggingProxy.(DriverLoggingProxy.java:16)

Same error occurs using log4jdbc. Has anyone a glimpse about that problem?

Thanks & kind regards, Hanno

A: 

I couldn't reproduce the problem. With the following configuration (using the "simple" binding):

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>sql-maven-plugin</artifactId>
    <version>1.3</version>
    <dependencies>
      <dependency>
        <groupId>jdbcdslog</groupId>
        <artifactId>jdbcdslog</artifactId>
        <version>1.0.5</version>
      </dependency>
      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.1</version>
      </dependency>
      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.6.1</version>
      </dependency>
      <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derbyclient</artifactId>
        <version>10.5.3.0_1</version>
      </dependency>
    </dependencies>
    <configuration>
      <driver>org.jdbcdslog.DriverLoggingProxy</driver>
      <url>jdbc:jdbcdslog:derby://localhost:1527/Q3854037-1.0-SNAPSHOT;targetDriver=org.apache.derby.jdbc.ClientDriver</url>
      <username>APP</username>
      <password>APP</password>
    </configuration>
    <executions>
      <execution>
        <id>drop-db-before-test-if-any</id>
        <phase>process-test-resources</phase>
        <goals>
          <goal>execute</goal>
        </goals>
        <configuration>
          <autocommit>true</autocommit>
          <sqlCommand>select * from FOO</sqlCommand>
          <!-- ignore error when database is not avaiable -->
          <onError>continue</onError>
        </configuration>
      </execution>
    </executions>
  </plugin>

Running mvn test just works

$ mvn test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Q3854037
[INFO]    task-segment: [test]
[INFO] ------------------------------------------------------------------------
...
[INFO] Executing commands
821 [main] INFO org.jdbcdslog.StatementLogger - java.sql.Statement.execute  select * from FOO 100 ms. at org.codehaus.mojo.sql.SqlExecMojo.execSQL(SqlExecMojo.java:815)
[INFO] 1 of 1 SQL statements executed successfully
...

Sure, I'm using another SLF4J binding but I don't think this difference is relevant (even with the binding for log4j, I could not reproduce the NoClassDefFoundError). Maybe check that your SLF4J jar is not corrupted (re-download it). By the way, you're missing a dependency on log4j as logging framework.

Pascal Thivent