即使我运行mvn hibernate3,hibernate.cfg.xml也没有被创建:hbm2cfgxml

时间:2012-08-28 19:09:51

标签: java hibernate maven hbm2java

当我运行mvn hibernate3:hbm2cfgxml时,它不会生成hibernate.cfg.xml文件。 但是它会生成pojos和daos,但不会生成hibernate.cfg.xml文件。

以下是我的pom.xml。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org /2001/XMLSchema-instance"=  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myhadoop.app</groupId>
<artifactId>my-app-hadoop</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app-hadoop</name>
<url>http://maven.apache.org</url>

<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-core</artifactId>
    <version>1.0.3</version>
</dependency>

<dependency>
    <groupId>org.hibernate </groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.1.6.Final</version>
</dependency>

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>3.0-alpha-1</version>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.6.6</version>
</dependency>

<dependency>
    <groupId>javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.12.1.GA </version>
</dependency>
</dependencies>
<repositories>
<repository>
    <id>jBoss-Repository</id>
    <url>https://repository.jboss.org/nexus/content/groups/public/</url>
    <releases>
       <enabled>true</enabled>
    </releases>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>        
 </repository>
 <repository>
    <id>mirrors.ibiblio</id>
    <url>http://mirrors.ibiblio.org/maven/mule/dependencies/maven2/</url>
    <releases>
       <enabled>true</enabled>
    </releases>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>        
 </repository>
 </repositories>
 <build>
<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>hibernate3-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
            <components>
                <component>
                    <name>hbm2ddl</name>
                         <implementation>jdbcconfiguration</implementation>
                </component>
                <component>
                    <name>hbm2hbmxml</name>
                    <implementation>jdbcconfiguration</implementation>
                    <outputDirectory>src/main/java/org/dbmxml</outputDirectory>
                </component>
                <component>
                    <name>hbm2dao</name>
                    <implementation>jdbcconfiguration</implementation>
                    <outputDirectory>src/main/java</outputDirectory>
                </component>
                <component>
                    <name>hbm2java</name>
                    <implementation>jdbcconfiguration</implementation>
                    <outputDirectory>src/main/java</outputDirectory>
                </component>

                <component>
                    <name>hbm2doc</name>
                    <implementation>jdbcconfiguration</implementation>
                    <outputDirectory>src/hbm2doc</outputDirectory>
                </component>

                <component>
                    <name>hbm2ddl</name>
                    <implementation>jdbcconfiguration</implementation>
                    <outputDirectory>src/hbm2ddl</outputDirectory>
                </component>
            </components>

            <componentProperties>
                <drop>true</drop>
                <packagename>org.hbm2dao</packagename>
                <configurationfile>/src/main/resources/hibernate.cfg.xml</configurationfile>
                <propertyFile>/src/main/resources/database.properties</propertyFile>
            </componentProperties>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>com.oracle</groupId>
                <artifactId>ojdbc</artifactId>
                <version>6</version>
                <scope>system</scope>
                <systemPath>D:/apps/oracle11g/product/11.2.0/dbhome_1/jdbc/lib/ojdbc6.jar</systemPath>
        </dependency>
    </dependencies>
  </plugin>
</plugins>

需要在pom.xml中添加什么才能生成hibernate.cfg.xml文件。

2 个答案:

答案 0 :(得分:1)

基于documentation,您需要创建如下所示的部分:

<component>
  <name>hbm2cfgxml</name>
  <implementation>...</implementation>
  ...
</component>

答案 1 :(得分:1)