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>
插件类路径与项目类路径是隔离的,根本不是跛脚。如果不是这样的话,它会非常令人讨厌(“不,你不能在你的项目中使用这个依赖项,因为它会刹车这个插件”)。所以必须在插件中声明它们才有意义。 – 2010-05-14 09:05:29
你当然是对的。经过4个小时的工作后才发泄。 – HDave 2010-05-14 13:05:30