Maven 2 hibernate3 maven:从父项目编译时,在子项目中找不到JDBC驱动程序
问题: 12:03:10126错误org.hibernate.tool.hbm2ddl.SchemaExport-架构导出失败org.hibernate.hibernate异常:未找到JDBC驱动程序类:com.mysql.JDBC.Driver 我有一个分为模块的项目:ParentProject和ChildModule。当我尝试编译ChildModule的pom.xml时,一切正常,maven成功地连接到数据库并创建表。然而,当从ParentProject编译时,我遇到了上面提到的错误(在执行hbm2ddl时)。你知道有什么问题吗 以下是我的pom.xml文件: ParentProject pom.xml:Maven 2 hibernate3 maven:从父项目编译时,在子项目中找不到JDBC驱动程序,maven-2,maven,hibernate3-maven-plugin,Maven 2,Maven,Hibernate3 Maven Plugin,问题: 12:03:10126错误org.hibernate.tool.hbm2ddl.SchemaExport-架构导出失败org.hibernate.hibernate异常:未找到JDBC驱动程序类:com.mysql.JDBC.Driver 我有一个分为模块的项目:ParentProject和ChildModule。当我尝试编译ChildModule的pom.xml时,一切正常,maven成功地连接到数据库并创建表。然而,当从ParentProject编译时,我遇到了上面提到的错误(在执行
<project ... >
<build>
<plugins>
<plugin>
<!-- JDK version used to compile project -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>JBOSS</id>
<name>JBoss Repository</name>
<url>http://repository.jboss.org/maven2/</url>
</repository>
<repository>
<id>Codehaus Snapshots</id>
<url>http://snapshots.repository.codehaus.org/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>Codehaus Snapshots</id>
<url>http://snapshots.repository.codehaus.org/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
<dependencyManagement>
<dependencies>
...
</dependencies>
</dependencyManagement>
<modules>
<module>../ChildModule</module>
</modules>
</project>
org.apache.maven.plugins
maven编译器插件
2.0.2
1.6
1.6
org.codehaus.mojo
hibernate3 maven插件
2.2
JBOSS
JBoss存储库
http://repository.jboss.org/maven2/
科德豪斯快照
http://snapshots.repository.codehaus.org/
真的
假的
科德豪斯快照
http://snapshots.repository.codehaus.org/
真的
真的
...
../ChildModule
ChildModule pom.xml:
<project ... >
<parent>
<groupId>com.somepackage</groupId>
<artifactId>ChildModule</artifactId>
<version>0.1</version>
<relativePath>../ParentProject/pom.xml</relativePath>
</parent>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-entities</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2java</goal>
</goals>
<configuration>
<components>
<component>
<name>hbm2java</name>
<implementation>configuration</implementation>
<outputDirectory>${generated-source-dir}</outputDirectory>
</component>
</components>
<componentProperties>
<configurationFile>src/main/resources/hibernate.cfg.xml</configurationFile>
<jdk5>true</jdk5>
</componentProperties>
</configuration>
</execution>
<execution>
<id>generate-schema</id>
<phase>process-classes</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
<configuration>
<componentProperties>
<outputfilename>schema.ddl</outputfilename>
<drop>true</drop>
<ejb3>false</ejb3>
</componentProperties>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.17</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.2.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
...
</dependencies>
<properties>
<generated-source-dir>generated-sources/hibernate3</generated-source-dir>
<generated-resource-dir>generated-resources/hibernate3</generated-resource-dir>
</properties>
</project>
com.somepackage
儿童模块
0.1
../ParentProject/pom.xml
...
org.apache.maven.plugins
maven编译器插件
2.3.1
1.6
1.6
org.codehaus.mojo
hibernate3 maven插件
生成实体
生成源
hbm2java
hbm2java
配置
${生成的源目录}
src/main/resources/hibernate.cfg.xml
真的
生成模式
进程类
hbm2ddl
schema.ddl
真的
假的
mysql
mysql连接器java
5.1.17
cglib
cglibnodep
2.2.2
...
生成源代码/hibernate3
生成的资源/hibernate3
您的父插件与子插件的mysql connector java不存在依赖关系。我建议将此依赖项添加(甚至移动)到家长的插件。您家长的插件不依赖于孩子拥有的mysql connector java
。我建议将此依赖项添加(甚至移动)到父插件。您的父插件不依赖于子插件的mysql connector java
。你试过添加它吗?是的,这解决了问题!非常感谢你的帮助!我已经发布了我的评论作为答案,所以现在你可以接受了。你父母的插件不依赖于mysql-connector-java
,而你的孩子依赖于mysql-connector-java
。你试过添加它吗?是的,这解决了问题!非常感谢你的帮助!我已经发布了我的评论作为答案,所以现在你可以接受了。