我需要能夠調用mvn clean install並且有maven調用hibernate3:hbm2hbmxml從數據庫中生成映射文件,而不是在調用hbm2java獲取Java文件,然後讓Maven編譯這些新創建的Java文件。 有沒有人做過這個?如何配置maven hbm2hbmxml和hbm2java在mvn中一個接一個地運行clean clean
感謝
我需要能夠調用mvn clean install並且有maven調用hibernate3:hbm2hbmxml從數據庫中生成映射文件,而不是在調用hbm2java獲取Java文件,然後讓Maven編譯這些新創建的Java文件。 有沒有人做過這個?如何配置maven hbm2hbmxml和hbm2java在mvn中一個接一個地運行clean clean
感謝
mvn clean dependency:copy-dependencies package
如果這是要執行的,該清理階段將首先執行(這意味着它將運行clean生命週期的所有前述階段,再加上清理階段本身),然後依賴:複製依賴關係目標,最終執行包階段(及其默認生命週期的所有先前構建階段)。
所以,也許:
mvn clean hibernate3:hbm2hbmxml hibernate3:hbm2java package
這就是說,我會建議對永久生成的類。這使你非常不靈活。
您的評論後,它似乎是從休眠插件「不明智」的行爲。您可以通過使用Maven antrun plugin「手動」將所需文件複製到所需的目錄來繞過該操作。
Bozho ,這並不完全是我如何理解這個問題的(這根本不是微不足道的,想要的工作流程涉及hibernate3插件的非常複雜的配置)。但也許我錯過了一些東西。 – 2010-01-18 07:54:42
我也不確定我是否收到了一切,但至少他應該試試這種方式,看看會發生什麼。 – Bozho 2010-01-18 08:14:25
感謝您的回覆。我在尋找的是能夠使這些目標成爲我持續集成過程的一部分。我設法使hbm2hbmxml工作,但將* .hbm.xml文件放在./target/hibernate3/generated-mappings/mypackage下。當我運行hbm2java時,出現「mypackage/Domain.hbm.xml not found」失敗。插件不知道在哪裏可以找到這些文件? 我通過添加
以下配置適用於我。 (樣本是用德比數據庫和1張表格)
mvn clean package可以做到這一切。
插件配置:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>hbm2hbmxml</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2hbmxml</goal>
</goals>
<configuration>
<components>
<component>
<name>hbm2hbmxml</name>
<outputDirectory>src/main/resources</outputDirectory>
</component>
</components>
</configuration>
</execution>
<execution>
<id>hbm2java</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2java</goal>
</goals>
<configuration>
<components>
<component>
<name>hbm2java</name>
<implementation>configuration</implementation>
</component>
</components>
<componentProperties>
<jdk5>true</jdk5>
<configurationfile>/src/main/resources/hibernate.cfg.xml
</configurationfile>
</componentProperties>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.4.2.0</version>
</dependency>
</dependencies>
的hibernate.cfg.xml:
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:derby://localhost:1527/demo</property>
<property name="connection.username">app</property>
<property name="connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
<property name="dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="connection.password">password</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="Tag.hbm.xml" />
</session-factory>
如果你想有你的模型的Java文件(通過復仇獲得)編譯,你不需要運行hbm2hbmxml。
插件配置:
<build>
<plugins>
<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>
</components>
<componentProperties>
<revengfile>/src/main/resources/reveng/model.reveng.xml</revengfile>
<propertyfile>/src/main/resources/META-INF/hibernate.properties</propertyfile>
<jdk5>true</jdk5>
<ejb3>true</ejb3>
</componentProperties>
</configuration>
<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>
</plugins>
</build>
hibernate.properties:
hibernate.dialect = org.hibernate.dialect.MySQLInnoDBDialect
hibernate.connection.driver_class = com.mysql.jdbc.Driver
hibernate.connection.url = jdbc:mysql://localhost:3306/YOUR_DB
hibernate.connection.username = yourUsrName
hibernate.connection.password= yourPwd
hibernate.default_schema = YOUR_DB
model.reveng。XML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<table-filter match-name=".*" package="your.package.here" />
</hibernate-reverse-engineering>
你用火的:
mvn clean hibernate3:hbm2java compile
,如果你希望它只是被解僱:
mvn clean compile
添加 「處決」 的標籤在你的插件定義
<executions>
<execution>
<phase>compile</phase>
<goals><goal>hbm2java</goal></goals>
</execution>
</executions>
這兩個答案都不是爲我開箱工作。經過一番研究,我能夠從數據庫中生成POJO。希望這個快速跟蹤某人。
只需生成java文件 - 不生成映射文件。
在src/test/resources/reveng/hibernate.cfg.xml中定義數據庫連接。使用測試分支以便這些文件不會被複制到可分發的工件中。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="pmSessionFactory">
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<!-- Note that we are pointing directly at the catalog so we can use
unqualified table names -->
<property name="hibernate.connection.url">jdbc:oracle:thin:@server.domain.com:1521:catalog</property>
<property name="hibernate.connection.password">login</property>
<property name="hibernate.connection.username">****</property>
<property name="hibernate.default_schema">PM</property>
</session-factory>
</hibernate-configuration>
創建要導入的表的列表。再次測試分支:SRC /測試/資源/復仇/ model.reveng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC
"-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<!-- This assumes your database connection is pointing to the proper catalog -->
<!-- To get all tables in the named schema, use the following
<schema-selection match-schema="PM" />
-->
<!-- to get only the named tables -->
<schema-selection match-schema="PM" match-table="PM_PROPERTY"/>
<schema-selection match-schema="PM" match-table="PM_APPLICATION"/>
<schema-selection match-schema="PM" match-table="PM_PROPERTY_TYPE"/>
</hibernate-reverse-engineering>
Hibernate3的Maven插件添加到您的POM
<build>
<plugins>
...
<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/com/me/examples/pm/data</outputDirectory>
<implementation>jdbcconfiguration</implementation>
</component>
</components>
<componentProperties>
<!-- Storing the reveng files in the test branch means we are not
deploying connection information-->
<revengfile>src/test/resources/reveng/model.reveng.xml</revengfile>
<configurationfile>src/test/resources/reveng/hibernate.cfg.xml</configurationfile>
<jdk5>true</jdk5>
<ejb3>true</ejb3>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>classes12</artifactId>
<version>10.2.0.1.0</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.1_3</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
運行Maven
mvn hibernate3:hbm2java
在您的pom中添加Hibernate 2插件:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>generate-mapping-files</id>
<phase>compile</phase>
<goals>
<goal>hbm2hbmxml</goal>
<goal>hbm2cfgxml</goal>
<goal>hbm2java</goal>
</goals>
...
然後在模型Reveng把這個。
<!-- Primary Tables -->
<schema-selection match-schema="TEST_SCHEMA" match-table="TEST_TABLE" />
然後,只需使用clean install
和模型類建立在Maven的項目會自動從數據庫中生成。
工作實例爲Hibernate3的,Maven的插件版本3.0 & 調用:hbm2java
<profile>
<id>hbm2java</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>3.0</version>
<configuration>
<hibernatetool>
<classpath>
<path location="${project.build.directory}/classes" />
</classpath>
<jdbcconfiguration propertyfile="${basedir}/helper/hibernate.properties" revengfile="${basedir}/helper/hibernate-reverse-engineering.xml"
reversestrategy="de.hibernate.ExampleStrategy" />
<hbm2java jdk5="true" ejb3="true" destdir="${project.build.sourceDirectory}" />
</hibernatetool>
</configuration>
<executions>
<execution>
<goals>
<goal>hbm2java</goal>
</goals>
<!-- must be compile or higher to find ExampleStrategy class in same project -->
<phase>compile</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.2.GA</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.1_3</version>
</dependency>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc6</artifactId>
<version>${ojdbc6.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
我更新了我的答案,說明如何 「手動」(基於Maven)將文件複製到所需的位置 – Bozho 2010-01-22 07:51:06