【发布时间】:2011-05-30 03:01:00
【问题描述】:
我正在尝试使用 maven 生成我的类和 hibernate.cfg.xml。 那么我的项目中有依赖于生成的java文件的类,所以我可能不得不在项目清理时执行这个过程?我不知道如何配置它来工作,所以这是一个问题。 好吧,我有一个没问题的 database.properties 文件和很多我修改过的 hbm.xml 文件。现在我想从 hbm.xml 文件和 database.properties 文件生成 hibernate.cfg.xml 和所有 java 文件。 我当前的 Maven 条目如下所示:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>hbm2java</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2java</goal>
</goals>
<configuration>
<components>
<component>
<name>hbm2java</name>
<implementation>configuration</implementation>
<outputDirectory>src/main/java</outputDirectory>
</component>
</components>
<componentProperties>
<jdk5>true</jdk5>
<ejb3>true</ejb3>
<propertyfile>src/main/resources/database.properties</propertyfile>
</componentProperties>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.8</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.1_3</version>
</dependency>
</dependencies>
</plugin>
谁能帮我解决这个问题?我真的不知道该怎么做才能让这件事发挥作用。
【问题讨论】:
-
generate-sources似乎是一个适合运行这个的phase。你得到的错误是什么,如果有的话?此外,如果您想在每次构建期间重新生成它,您不希望将生成的源代码放在src/main/java中。 -
我通过编写自己的 maven 插件解决了我的问题,该插件负责在配置文件中添加 xml 映射元素。如果有人对此插件感兴趣,请给我留言。
标签: hibernate plugins maven hbm2java