2014-09-03 22 views
0

我試圖按照第7章的教程在這個網上書:http://books.sonatype.com/mvnex-book/reference/index.htmlMVN Hibernate3的:就是hbm2ddl在教程中失敗

本教程的目的是展示一個Web應用程序與Spring框架與Hibernate,我被卡住在這裏:

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 

回答

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>

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>