如何配置 hbm2java maven2 插件为所有映射文件生成 POJO
我正在尝试将我的 ant 构建迁移到 maven2。在我的 build.xml 中,我通过以下方式调用 hbm2java:
<hibernatetool destdir="/src/generated/">
<configuration configurationfile="${env.ITP_HOME}/core/xml/hibernate/hibernate.cfg.xml">
<fileset dir="/xml/hibernate">
<include name="*.hbm.xml"/>
</fileset>
</configuration>
<hbm2java/>
</hibernatetool>
我的 hibernate.cfg.xml 是:
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
</session-factory>
在我的 maven2 POM 文件中,我有:
<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>
<configurationfile>/src/main/resources/hibernate.cfg.xml</configurationfile>
</componentProperties>
</configuration>
</execution>
但是当执行 mvn hibernate3:hbm2java 时,我发现没有生成任何文件,除非它们都列在 hibernate.cfg.xml 中。 有没有办法在maven配置中指定类似于ant任务的文件集?
谢谢, 瑙尔
I am trying to migrate my ant build to maven2. in my build.xml I invoke the hbm2java in the following way:
<hibernatetool destdir="/src/generated/">
<configuration configurationfile="${env.ITP_HOME}/core/xml/hibernate/hibernate.cfg.xml">
<fileset dir="/xml/hibernate">
<include name="*.hbm.xml"/>
</fileset>
</configuration>
<hbm2java/>
</hibernatetool>
my hibernate.cfg.xml is:
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
</session-factory>
in my maven2 POM file I have:
<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>
<configurationfile>/src/main/resources/hibernate.cfg.xml</configurationfile>
</componentProperties>
</configuration>
</execution>
but when executing mvn hibernate3:hbm2java
i see no files get generated unless they are all listed in hibernate.cfg.xml.
Is there a way to specify a fileset in the maven configuration similar to the ant task?
thanks,
naor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是唯一的方法,但我会首先使用
hbm2cfgxml
生成hibernate.cfg.xml
配置文件,其中包括
条目,然后是生成 POJO 的hbm2java
目标。下面是作为构建的一部分执行此操作的配置:其中
src/main/database.properties
文件包含以下信息此设置假定放置了
.hbm.xml
在src/main/resources
中(因此将被复制到target/classes
中以供hbm2java
处理)。I'm not sure this is the only way but I would use
hbm2cfgxml
first to generate ahibernate.cfg.xml
configuration file including the<mapping resource="..."/>
entries and then thehbm2java
goal to generate the POJOs. Below, a configuration doing this as part of your build:Where the
src/main/database.properties
file contains the following informationThis setup assumes your
.hbm.xml
are placed insrc/main/resources
(and will thus be copied intotarget/classes
for the processing byhbm2java
).