2013-03-19 22 views
1

我使用Maven 3.0.3,MySQL的5.5使用Maven插件SQL(V 1.5),以創建一個測試數據庫爲我的JUnit測試...當SQL插件無法連接到數據庫時,是否可以讓Maven輸出自定義錯誤消息?

   <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>sql-maven-plugin</artifactId> 
        <version>1.5</version> 
        <dependencies> 
         <dependency> 
          <groupId>mysql</groupId> 
          <artifactId>mysql-connector-java</artifactId> 
          <version>5.1.18</version> 
         </dependency> 
        </dependencies> 
        <!-- common configuration shared by all executions --> 
        <configuration> 
         <driver>com.mysql.jdbc.Driver</driver> 
         <url>jdbc:mysql://${test.mysql.db.host}:${test.mysql.db.port}/${test.mysql.db.sid}</url> 
         <username>${test.mysql.db.user}</username> 
         <password>${test.mysql.db.password}</password> 
         <!--all executions are ignored if -Dmaven.test.skip=true --> 
         <skip>${maven.test.skip}</skip> 
        </configuration> 

        <executions> 
         <execution> 
          <id>create-test-db</id> 
          <phase>compile</phase> 
          <goals> 
           <goal>execute</goal> 
          </goals> 
          <configuration> 
           <url>jdbc:mysql://${test.mysql.db.host}:${test.mysql.db.port}</url> 
           <username>${test.mysql.db.user}</username> 
           <password>${test.mysql.db.password}</password> 
           <autocommit>true</autocommit> 
           <sqlCommand>create database if not exists ${test.mysql.db.sid}</sqlCommand> 
          </configuration> 
         </execution> 
        </executions> 

如果連接不能進行(因爲用戶還沒有被創建或者具有錯誤的權限),所以我想顯示一個比事情死的時候默認打印的更友好的錯誤信息。有誰知道這是怎麼做到的嗎?我願意使用除Maven SQL插件之外的其他插件。

謝謝 - 戴夫

回答

0

由於錯誤信息是具體到每個數據庫(你會得到比MySQL在甲骨文不同的錯誤消息),並且每個數據庫以不同的方式處理這些錯誤,也可能不是一個通用的方法。 Spring框架將數據庫錯誤封裝到一個豐富的異常層次結構中,您可能想看看它們是如何以通用方式處理這些錯誤的。

一種選擇是擴展Maven SQL插件並在那裏添加該功能。如果你可以在數據庫中以通用的方式做到這一點,甚至更好,但我想如果你可以讓它適用於MySQL,那對你已經有所幫助了。

爲什麼你要提供更友好的錯誤信息的具體原因?

+0

我想提供更友好的錯誤消息,以便運行pom的其他開發人員知道在發生故障時該做什麼。如果這有助於回答這個問題,我們將一直使用MySQL。 – Dave 2013-03-20 17:10:39

+0

創建一個列出常見錯誤消息的Wiki頁面不是更容易嗎,它們是什麼意思以及如何解決它們? – nwinkler 2013-03-20 20:18:03

+0

不幸的是,沒有人閱讀電子郵件或維基頁面。正如我所說的,我想讓這個過程變得非常簡單,只要他們看到錯誤信息,他們就知道該做什麼,而無需閱讀任何內容或訪問任何外部網站。 – Dave 2013-03-25 18:26:19