mvn hibernate3:hbm2ddl在教程中失败了

时间:2014-09-03 06:40:25

标签: java hibernate maven

我正在尝试按照此在线书籍第7章中的教程:http://books.sonatype.com/mvnex-book/reference/index.html

本教程旨在演示一个带有hibernate的Spring Framework的Web应用程序,我被困在这里:

mvn hibernate3:hbm2ddl

...
<build>
    <finalName>simple-webapp</finalName>
    <plugins>
        <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <dependencies>
                        <dependency>
                            <groupId>hsqldb</groupId>
                            <artifactId>hsqldb</artifactId>
                            <version>1.8.0.7</version>
                        </dependency>
                </dependencies>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
                <artifactId>hibernate3-maven-plugin</artifactId>
                <version>2.0</version>
                <configuration>
                    <components>
                        <component>
                            <name>hbm2ddl</name>
                            <implementation>annotationconfiguration</implementation>
                        </component>
                    </components>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>hsqldb</groupId>
                        <artifactId>hsqldb</artifactId>
                        <version>1.8.0.7</version>
                    </dependency>
                    <dependency>
                <groupId>org.hibernate.javax.persistence</groupId>
                <artifactId>hibernate-jpa-2.0-api</artifactId>
                <version>1.0.0.Final</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <version>3.6.7.Final</version>
            </dependency>
                </dependencies>
        </plugin>
    </plugins>
</build>

错误信息如下。任何见解或指针将不胜感激。感谢。

@localhost simple-webapp]$ mvn hibernate3:hbm2ddl
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for     org.sonatype.mavenbook.multispring:simple-webapp:war:1.0
[WARNING] 'build.plugins.plugin.version' for org.mortbay.jetty:maven-jetty-plugin is     missing. @ org.sonatype.mavenbook.multispring:simple-webapp:[unknown-version],     /home/abigail/workspace/simple-parent/simple-webapp/pom.xml, line 46, column 21
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-    plugin is missing. @ org.sonatype.mavenbook.multispring:simple-parent:1.0,     /home/abigail/workspace/simple-parent/pom.xml, line 29, column 12
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the     stability of your build. 
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such     malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Simple Web Application 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> hibernate3-maven-plugin:3.0:hbm2ddl (default-cli) > compile @ simple-webapp     >>>
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ simple-webapp ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e.     build is platform dependent!
[INFO] skip non existing resourceDirectory /home/abigail/workspace/simple-parent/simple-    webapp/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ simple-webapp ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] <<< hibernate3-maven-plugin:3.0:hbm2ddl (default-cli) < compile @ simple-webapp     <<<
[INFO] 
[INFO] --- hibernate3-maven-plugin:3.0:hbm2ddl (default-cli) @ simple-webapp ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.959 s
[INFO] Finished at: 2014-09-03T02:35:24-04:00
[INFO] Final Memory: 12M/208M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl     (default-cli) on project simple-webapp: There was an error creating the AntRun task.     NullPointerException -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the     following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

3 个答案:

答案 0 :(得分:0)

尝试为maven-jetty-plugin的插件添加版本,看看是否能解决问题,因为有警告说:

[WARNING] 'build.plugins.plugin.version' for org.mortbay.jetty:maven-jetty-plugin is     missing. @ org.sonatype.mavenbook.multispring:simple-webapp:[unknown-version],     /home/abigail/workspace/simple-parent/simple-webapp/pom.xml, line 46, column 21
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-    plugin is missing. @ org.sonatype.mavenbook.multispring:simple-parent:1.0,     /home/abigail/workspace/simple-parent/pom.xml, line 29, column 12

例如:

<version>4.2.14</version>

答案 1 :(得分:0)

你可以试试下面的插件。

<plugin>
    <!-- Run "mvn hibernate3:hbm2ddl" to generate schema -->
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
    <version>${hibernate3.maven.plugin.version}</version>

    <configuration>
        <hibernatetool>
            <annotationconfiguration propertyfile="src/main/resources/${hibernate.properties}" />
            <hbm2ddl update="true" create="true" export="false"
                     outputfilename="${hibernate.hbm2ddl.sqlfile}" format="true"
                     console="true" />
        </hibernatetool>
    </configuration>
</plugin>

而不是

<groupId>org.codehaus.mojo</groupId>
                <artifactId>hibernate3-maven-plugin</artifactId>
                <version>2.0</version>
                <configuration>
                    <components>
                        <component>
                            <name>hbm2ddl</name>
                            <implementation>annotationconfiguration</implementation>
                        </component>
                    </components>
                </configuration>

答案 2 :(得分:0)

我遇到了与您相同的问题(使用Java 8),并通过将插件的版本从2.0切换到2.2 来解决了该问题。如果尝试使用较新的版本,它似乎会再次中断。

想知道有没有比反复试验以及广泛使用搜索引擎更好的方法来解决此类版本问题。

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>hibernate3-maven-plugin</artifactId>
  <version>2.2</version>
  <configuration>
    <components>
      <component>
        <name>hbm2ddl</name>
        <implementation>annotationconfiguration</implementation>
      </component>
    </components>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>hsqldb</groupId>
      <artifactId>hsqldb</artifactId>
      <version>1.8.0.7</version>
    </dependency>
  </dependencies>
</plugin>