我有一个使用 Maven 构建的 Java 项目。我现在正试图让 hibernate3-maven-plugin 运行 hbm2ddl 工具来生成一个 schema.sql 文件,我可以使用它来从我的带注释的域类中创建数据库模式。这是一个使用 Hibernate 作为提供者的 JPA 应用程序。
在我的 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>