2010-01-18 4 views
9

mvn 새로 설치를 호출하고 maven을 호출하여 hibernate3 : hbm2hbmxml을 호출하여 데이터베이스에서 매핑 파일을 생성하고 hbm2java를 호출 할 수 있어야합니다. Java 파일을 가져온 다음 새로 작성한 Java 파일을 maven으로 컴파일하십시오. 이전에이 작업을 수행 한 사람이 있습니까?mvn 새로 설치에서 maven hbm2hbmxml 및 hbm2java를 차례대로 구성하는 방법

감사합니다 (그것은 깨끗한 라이프 사이클의 모든 선행 단계를 실행합니다 의미

실행했다이, 깨끗한 단계가 먼저 실행됩니다
+0

위해 나는 "수동으로"(받는다는 통해) 원하는 위치 – Bozho

답변

1

Maven lifecycle

mvn clean dependency:copy-dependencies package 

플러스 깨끗한 상 그 다음 종속성 : 복사 의존성 목표를 설정하고 마지막으로 패키지 단계 (및 기본 수명주기의 모든 사전 빌드 단계)를 실행합니다. 아마도

그래서, : 나는 끊임없이 생성 클래스에 추천이라고 말했다

mvn clean hibernate3:hbm2hbmxml hibernate3:hbm2java package 

. 이것은 당신이 매우 융통성있게 만듭니다.

귀하의 의견을 듣고 나서, 그것은 최대 절전 모드 플러그인에서 "현명하지 않은"동작처럼 보입니다. Maven antrun plugin을 사용하여 필요한 파일을 원하는 디렉토리에 "수동으로"복사하여 우회 할 수 있습니다.

+0

Bozho에 파일을 복사하는 방법을 나타 내 대답 업데이트 , 이것은 정확히 내가 질문을 이해하는 방법은 아니다. (이것은 결코 사소하지 않다. 원하는 워크 플로우는 hibernate3 플러그인의 까다로운 구성을 포함한다.) 하지만 어쩌면 뭔가를 놓친 것일 수도 있습니다. –

+0

나는 또한 모든 것을 얻었는지 확신하지 못했지만, 적어도 그는 이런 식으로 시도해야하고, 어떤 일이 일어나는지보아야한다. – Bozho

+0

답장을 보내 주셔서 감사합니다. 내가 찾고있는 것은 이러한 목표를 나의 지속적인 통합 프로세스의 일부로 할 수 있어야한다는 것입니다. 나는 hbm2hbmxml 작업을 만들었지 만 * .hbm.xml 파일을 ./target/hibernate3/generated-mappings/mypackage에 저장합니다. hbm2java를 실행하면 "mypackage/Domain.hbm.xml을 찾을 수 없습니다"라는 오류 메시지가 나타납니다. 플러그인이 파일을 찾을 위치를 알고 있어야하지 않습니까? 항목을 추가하여 실행했고 hbm2java가 소스 코드를 생성하지만 다시 대상 폴더 아래에 Java 파일을 배치하고 컴파일 할 때 해당 파일을 컴파일하지 않습니다. 실마리가 있습니까? 감사 – sebastianr

0

다음 구성이 적용됩니다. (샘플은 Derby 데이터베이스와 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> 

13

당신이 당신의 모델 자바 파일을 갖고 싶어 (reveng에 의해 획득) 컴파일하면 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은 :

mvn clean hibernate3:hbm2java compile 

당신이 단지와 해고하려는 경우 :

<?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 compile 

는 플러그인 정의에서 "실행"태그를 추가

  <executions> 
       <execution> 
        <phase>compile</phase> 
        <goals><goal>hbm2java</goal></goals> 
       </execution> 
      </executions> 
5

두 답변 상자에서 나를 위해 일했다. 약간의 연구 끝에 데이터베이스에서 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/테스트/자원/reveng/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은 받는다는 플러그인을 추가

<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> 

실행 받는다는

mvn hibernate3:hbm2java 
0

최대 절전 모드 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 및 모델 클래스를 사용하여 받는다는에서 프로젝트를 빌드

데이터베이스에서 자동으로 생성됩니다.

1

작업 예 Hibernate3는-받는다는 - 플러그인 버전 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> 
관련 문제