2010-10-04 41 views
2

我正在嘗試在maven2中使用jdbcdslog或log4jdbc。 - 我想記錄所有由mvn-sql執行的SQL。在maven2中使用jdbcdslog或log4jdbc

我安裝了SLF4J的API(1.6.1),SLF4J-log4j12(1.6.1)和jdbcdslog(1.0.5)瓶到我的本地maven2的回購,在我的pom.xml配置如下:

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

執行這導致:

java.lang.NoClassDefFoundError:組織/ SLF4J /的LoggerFactory 在org.jdbcdslog.DriverLoggingProxy(DriverLoggingProxy.java:16)使用log4jdbc發生

同樣的錯誤。有沒有人瞥見這個問題?

感謝&親切的問候, 漢諾

回答

0

我無法重現該問題。用下面的配置(使用「簡單」綁定):

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

運行mvn test只是工作

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

當然,我在使用其他SLF4J綁定,但我不認爲這種差異是相關的(即使對於log4j的綁定,我也無法重現NoClassDefFoundError)。也許檢查你的SLF4J jar沒有損壞(重新下載它)。順便說一句,你錯過了對log4j作爲日誌框架的依賴。