[英]How to configure different components in maven for hibernate
I'm currently reverse engineering table from a DB, I wish to produce xml mappings, java pojo classes and java dao classes. 我目前正在从数据库反向工程表,我希望产生xml映射,java pojo类和java dao类。 I would like to store the resulting classes in different package folders eg app.myapp.dao, app.myapp.pojo and app.myapp.dao.
我想将生成的类存储在不同的包文件夹中,例如app.myapp.dao,app.myapp.pojo和app.myapp.dao。 I would like to configure my pom to have separate 'component' configurations, so for example for hbm2dao, look for a specific hibernate.reveng.xml file which would contain info and tell the class generation to add package app.myapp.dao to the top of the class.
我想将pom配置为具有单独的“组件”配置,因此对于hbm2dao,例如,查找包含信息的特定hibernate.reveng.xml文件,并告诉类生成将包app.myapp.dao添加到一流的。 My current set up is:
我当前的设置是:
<configuration>
<components>
<component>
<name>hbm2java</name>
<outputDirectory>src/main/java</outputDirectory>
<implementation>jdbcconfiguration</implementation>
</component>
<component>
<name>hbm2dao</name>
<outputDirectory>src/main/java</outputDirectory>
<implementation>jdbcconfiguration</implementation>
</component>
</components>
<componentProperties
<revengfile>src/main/resources/hibernate.reveng.xml</revengfile
<configurationfile>src/main/resources/hibernate.cfg.xml</configurationfile>
<jdk5>true</jdk5>
<ejb3>false</ejb3>
</componentProperties>
</configuration>
My current set up can only use one version of hibernate.reveng.xml for all 3 types of generation(hbm2dao, hbm2java, hbm2hbxml) So my question is how do i set up my pom to use 3 separate hibernate.reveng.xml files, so i can configure the package info and put the generated classes in different locations? 我目前的设置只能将一种版本的hibernate.reveng.xml用于所有3种类型的生成(hbm2dao,hbm2java,hbm2hbxml),所以我的问题是我如何将pom设置为使用3个单独的hibernate.reveng.xml文件,所以我可以配置包信息并将生成的类放在不同的位置? is it possible?
可能吗? Thanks
谢谢
Instead of having a shared configuration element in plugin/configuration you have to move it to every separate execution in plugin/executions/execution/configuration . 与其在plugin / configuration中没有共享的配置元素,您必须将其移到plugin / executions / execution / configuration中的每个单独的执行中。
So for example if you have your plugin currently configured like this: 因此,例如,如果您的插件当前配置如下:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<components>
<component>
<name>hbm2java</name>
<outputDirectory>src/main/java</outputDirectory>
<implementation>jdbcconfiguration</implementation>
</component>
<component>
<name>hbm2dao</name>
<outputDirectory>src/main/java</outputDirectory>
<implementation>jdbcconfiguration</implementation>
</component>
</components>
<componentProperties
<revengfile>src/main/resources/hibernate.reveng.xml</revengfile
<configurationfile>src/main/resources/hibernate.cfg.xml</configurationfile>
<jdk5>true</jdk5>
<ejb3>false</ejb3>
</componentProperties>
</configuration>
<executions>
<execution>
<id>hbm2java-execution</id>
<phase>compile</phase>
<goals>
<goal>hbm2java</goal>
</goals>
</execution>
<execution>
<id>hbm2dao-execution</id>
<phase>compile</phase>
<goals>
<goal>hbm2dao</goal>
</goals>
</execution>
</executions>
<dependencies>
...
</dependencies>
</plugin>
Change it to: 更改为:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>hbm2java-execution</id>
<phase>compile</phase>
<goals>
<goal>hbm2java</goal>
</goals>
<configuration>
<!-- hbm2java component only -->
<components>
<component>
<name>hbm2java</name>
<outputDirectory>src/main/java</outputDirectory>
<implementation>jdbcconfiguration</implementation>
</component>
</components>
<!-- hbm2java component properties -->
<componentProperties
<revengfile>src/main/resources/hibernate.reveng.xml</revengfile
<configurationfile>src/main/resources/hibernate.cfg.xml</configurationfile>
<packagename>app.myapp.pojo</packagename>
<jdk5>true</jdk5>
<ejb3>false</ejb3>
</componentProperties>
</configuration>
</execution>
<execution>
<id>hbm2dao-execution</id>
<phase>compile</phase>
<goals>
<goal>hbm2dao</goal>
</goals>
<configuration>
<!-- hbm2dao component only -->
<components>
<component>
<name>hbm2dao</name>
<outputDirectory>src/main/java</outputDirectory>
<implementation>jdbcconfiguration</implementation>
</component>
</components>
<!-- hbm2dao component properties -->
<componentProperties
<revengfile>src/main/resources/hibernate.reveng.xml</revengfile
<configurationfile>src/main/resources/hibernate.cfg.xml</configurationfile>
<packagename>app.myapp.dao</packagename>
<jdk5>true</jdk5>
<ejb3>false</ejb3>
</componentProperties>
</configuration>
</execution>
</executions>
<dependencies>
...
</dependencies>
</plugin>
See how now you can specify different packagename property values for hbm2java and hbm2dao. 请参见现在如何为hbm2java和hbm2dao指定不同的packagename属性值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.