2010-05-14 38 views
1

我有一個用Maven構建的Java項目。我現在試圖讓hibernate3-maven-plugin運行hbm2ddl工具來生成一個schema.sql文件,我可以使用它從我的註釋域類創建數據庫模式。這是一個使用Hibernate作爲提供者的JPA應用程序。如何獲取hibernate3-maven-plugin hbm2ddl來查找JDBC驅動程序?

在我的persistence.xml文件我召喚出了MySQL驅動程序:

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> 
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> 

當我運行Maven,我把它處理我所有的課,但是當它進入輸出模式,我得到以下錯誤:

ERROR org.hibernate.connection.DriverManagerConnectionProvider - JDBC Driver class not found: com.mysql.jdbc.Driver 
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 

我有MySQL驅動程序作爲此模塊的依賴項。但是,似乎hbm2ddl工具找不到它。我會猜想Maven插件會知道爲本驅動程序搜索本地Maven文件庫。是什麼賦予了?

我的pom.xml的相關部分是這樣的:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>hibernate3-maven-plugin</artifactId> 
    <executions> 
     <execution> 
     <phase>process-classes</phase> 
     <goals> 
      <goal>hbm2ddl</goal> 
      </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <components> 
      <component> 
      <name>hbm2ddl</name> 
      <implementation>jpaconfiguration</implementation> 
      </component> 
     </components> 
     <componentProperties> 
      <persistenceunit>my-unit</persistenceunit> 
     </componentProperties> 
    </configuration>  
</plugin> 

回答

0

我想通了。您必須將相應的JDBC驅動程序作爲PLUGIN的依賴項添加。將它作爲模塊的依賴項添加不起作用。這對我來說似乎令人驚訝,實際上也是一種跛腳。

<dependencies> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <type>jar</type> 
      <version>5.0.8</version> 
     </dependency> 
    </dependencies> 
+0

插件類路徑與項目類路徑是隔離的,根本不是跛腳。如果不是這樣的話,它會非常令人討厭(「不,你不能在你的項目中使用這個依賴項,因爲它會剎車這個插件」)。所以必須在插件中聲明它們纔有意義。 – 2010-05-14 09:05:29

+0

你當然是對的。經過4個小時的工作後才發泄。 – HDave 2010-05-14 13:05:30