在安装阶段执行ddl-generation

时间:2013-12-11 21:08:00

标签: java hibernate maven plugins ddl

我找到ddl-generation的此页面,我的当前代码如下:

        <plugin>
            <!-- run "mvn clean install -Dmaven.test.skip=true -X hibernate3:hbm2ddl" to generate a schema -->
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>hibernate3-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <components>
                    <component>
                        <name>hbm2ddl</name>
                        <implementation>jpaconfiguration</implementation>
                    </component>
                </components>
                <componentProperties>
                    <persistenceunit>Default</persistenceunit>
                    <outputfilename>schema.ddl</outputfilename>
                    <drop>false</drop>
                    <create>true</create>
                    <export>false</export>
                    <format>true</format>
                </componentProperties>
            </configuration>
        </plugin>

使用命令“mvn clean install -Dmaven.test.skip = true -X hibernate3:hbm2ddl”可以正常工作但是“mvn clean install”不会生成ddl。 我怎么能改变这个?

谢谢!

1 个答案:

答案 0 :(得分:0)

您需要将hbm2ddl目标bind the execution改为maven lifecycle phase。您可以绑定到install阶段,但是在生成ddl的情况下,我建议generate-sources阶段(这将允许您在安装之前在生成的工件中打包生成的ddl)。

例如添加

<executions>
  <execution>
      <id>execute-hbm2ddl</id>
      <phase>generate-sources</phase>
      <goals>
          <goal>hbm2ddl</goal>
      </goals>
      ... <!-- configuration here -->
  </execution>
</executions>

获取

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>hibernate3-maven-plugin</artifactId>
        <version>2.2</version>
        <executions>
          <execution>
            <id>execute-hbm2ddl</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>hbm2ddl</goal>
            </goals>
            <configuration>
                <components>
                    <component>
                        <name>hbm2ddl</name>
                        <implementation>jpaconfiguration</implementation>
                    </component>
                </components>
                <componentProperties>
                    <persistenceunit>Default</persistenceunit>
                    <outputfilename>schema.ddl</outputfilename>
                    <drop>false</drop>
                    <create>true</create>
                    <export>false</export>
                    <format>true</format>
                </componentProperties>
            </configuration>
          </execution>
        </executions>
    </plugin>