1

当我运行 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 文件。

4

2 回答 2

1

根据您需要创建如下部分的文档:

<component>
  <name>hbm2cfgxml</name>
  <implementation>...</implementation>
  ...
</component>
于 2012-08-29T05:46:17.463 回答
1

此外,除了上述答案之外,我认为您在 POM 中有重复声明“hbm2ddl”组件。

您可以参考: http ://hop2croft.wordpress.com/2011/05/08/creating-java-domain-objects-with-the-maven-hibernate-plugin/#highlighter_819265 和 https://forum.hibernate。 org/viewtopic.php?f=6&t=1008209&view=previous

于 2012-08-29T06:18:14.210 回答