Maven权威指南 第七章数据库生成不了的解决方法
初学Maven,必然是看\<\
书中7.7节原文写到:
7.7. 运行这个Web应用
为了运行这个web应用,你首先需要使用Hibernate3插件构造数据库。为此,在项目simple-webapp目录下运行如下命令:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 >$ mvn hibernate3:hbm2ddl >[INFO] Scanning for projects... >[INFO] Searching repository for plugin with prefix: >'hibernate3'. >[INFO] org.codehaus.mojo: checking for updates from central >[INFO] ------------------------------------------------------------------------ >[INFO] Building Chapter 7 Simple Web Application >[INFO] task-segment: [hibernate3:hbm2ddl] >[INFO] ------------------------------------------------------------------------ >[INFO] Preparing hibernate3:hbm2ddl >... >10:24:56,151 INFO org.hibernate.tool.hbm2ddl.SchemaExport - export complete >[INFO] ------------------------------------------------------------------------ >[INFO] BUILD SUCCESSFUL >[INFO] ------------------------------------------------------------------------ >
实际上并非如此,直接用随书附带的源码,会得到如下提示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building Chapter 7 Simple Web Application [INFO] task-segment: [hibernate3:hbm2ddl] [INFO] ------------------------------------------------------------------------ [INFO] Preparing hibernate3:hbm2ddl [INFO] [resources:resources {execution: default-resources}] [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory E:\simple-parent\simple-webapp\src\main\resources [INFO] [hibernate3:hbm2ddl {execution: default-cli}] [INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Could not get ConfigurationTask. [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2 seconds [INFO] Finished at: Mon Feb 06 12:42:29 CST 2012 [INFO] Final Memory: 10M/25M [INFO] ------------------------------------------------------------------------ |
Could not get ConfigurationTask.
这个错误我Google了一下,只找到一个相关的页面,页面上是系统变量的JDK写错了,和我这边似乎没什么关系。
如果我去除POM中的hibernate3-maven-plugin,则运行时候会显示如下错误:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | simple-webapp>mvn hibernate3:hbm2ddl [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'hibernate3'. [INFO] ------------------------------------------------------------------------ [INFO] Building Chapter 7 Simple Web Application [INFO] task-segment: [hibernate3:hbm2ddl] [INFO] ------------------------------------------------------------------------ [INFO] Preparing hibernate3:hbm2ddl [INFO] [resources:resources {execution: default-resources}] [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory E:\simple-parent\simple-webapp\src\main\resources [INFO] [hibernate3:hbm2ddl {execution: default-cli}] 12:59:55,351 INFO org.hibernate.cfg.Environment - Hibernate 3.3.1.GA 12:59:55,357 INFO org.hibernate.cfg.Environment - hibernate.properties not found 12:59:55,362 INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist 12:59:55,367 INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling [INFO] Configuration XML file loaded: jar:file:/C:/Users/Niphor/.m2/repository/org/sonatype/mavenbook/ch07/simple-persist/0.6-SNAPSHOT/simple-persist-0.6-SNAPSHOT.jar!/hibernate.cfg.xml 12:59:55,418 INFO org.hibernate.cfg.Configuration - configuring from url: jar:file:/C:/Users/Niphor/.m2/repository/org/sonatype/mavenbook/ch07/simple-persist/0.6-SNAPSHOT/simple-persist-0.6-SNAPSHOT.jar!/hibernate.cfg.xml [INFO] ------------------------------------------------------------------------ [ERROR] FATAL ERROR [INFO] ------------------------------------------------------------------------ [INFO] An AnnotationConfiguration instance is required to use <mapping class="org.sonatype.mavenbook.weather.model.Atmosphere"/> [INFO] ------------------------------------------------------------------------ |
看样子是没标明用annotation
,所以提示要annotationConfiguration
的实例。
Google"hibernate3:hbm2ddl"
你会得到一些中文开发者的解决方法,一般都是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>hibernate3-maven-plugin</artifactId> <version>2.2</version> <configuration> <componentProperties> <jdk5>true</jdk5> <implementation>annotationconfiguration</implementation> </componentProperties> </configuration> <dependencies> <dependency> <groupId>hsqldb</groupId> <artifactId>hsqldb</artifactId> <version>1.8.0.7</version> </dependency> </dependencies> </plugin> |
而源码上是
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>hibernate3-maven-plugin</artifactId> <version>2.1</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> |
我把
1 2 3 4 | <componentProperties> <jdk5>true</jdk5> <implementation>annotationconfiguration</implementation> </componentProperties> |
替换成了
1 2 3 4 5 6 | <components> <component> <name>hbm2ddl</name> <implementation>annotationconfiguration</implementation> </component> </components> |
结果不行,报错依旧,最后我发现插件版本网上2.2,而我的源码是2.1,改成2.2立即成功,且完全不需要去写
1 | <jdk5>true</jdk5> |
即
1 2 3 4 5 6 7 8 9 | <version>2.2</version> <configuration> <components> <component> <name>hbm2ddl</name> <implementation>annotationconfiguration</implementation> </component> </components> </configuration> |
直接这样就可以了…
为了这个恼人的Bug我用了数小时,结果居然是这样的…让我直接很悲哀啊…
[TOC]