項目集成了 hibernate3-maven-plugin插件後,一旦運行mvn cobertura:cobertura就會莫名的報一些實體類CLASSNOTFOUND的錯,最後在http://appfuse.547863.n4.nabble.com/cobertura-conflicts-with-hibernate3-td579218.html 當中找到了答案,原來是hibernate3-maven-plugin和cobertura有衝突(有BUG),最後解決辦法是在MAVEN配置文件 setting.xml中加入如下配置:html
- <profile>
- <id>lazy-hibernate3</id>
- <properties><hibernate3.execute.phase>package</hibernate3.execute.phase></properties>
- </profile>
而後在pom.xml 修改hibernate3-maven-plugin的執行階段,修改以下:java
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>hibernate3-maven-plugin</artifactId>
- <version>2.2</version>
- <dependencies>
- <dependency>
- <groupId>${jdbc.groupId}</groupId>
- <artifactId>${jdbc.artifactId}</artifactId>
- <version>${jdbc.version}</version>
- </dependency>
- </dependencies>
- <configuration>
- <components>
- <component>
- <name>hbm2ddl</name>
- <implementation>annotationconfiguration</implementation>
- </component>
- </components>
- <componentProperties>
- <drop>true</drop>
- <jdk5>true</jdk5>
- <propertyfile>target/classes/jdbc.properties</propertyfile>
- </componentProperties>
- <skip>${maven.test.skip}</skip><!--很重要,能夠控制是否要在package時從新建表-->
- </configuration>
- <executions>
- <execution>
- <phase>${hibernate3.execute.phase}</phase>
- <goals>
- <goal>hbm2ddl</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
注意紅色字體部分。mysql
而後再在pom.xml加入如下配置:sql
- <properties>
- <dbunit.dataTypeFactoryName>org.dbunit.ext.mysql.MySqlDataTypeFactory</dbunit.dataTypeFactoryName>
- <dbunit.operation.type>CLEAN_INSERT</dbunit.operation.type>
- <hibernate.dialect>org.hibernate.dialect.MySQL5InnoDBDialect</hibernate.dialect>
- <jdbc.groupId>mysql</jdbc.groupId>
- <jdbc.artifactId>mysql-connector-java</jdbc.artifactId>
- <jdbc.version>5.1.13</jdbc.version>
- <jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName>
- <jdbc.url><![CDATA[jdbc:mysql://localhost/test?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8]]></jdbc.url>
- <jdbc.username>root</jdbc.username>
- <jdbc.password>root</jdbc.password>
- <hibernate3.execute.phase>package</hibernate3.execute.phase>
- </properties>
注意 <hibernate3.execute.phase>package</hibernate3.execute.phase> 配置app
之後輸入mvn cobertura:cobertura -dPlazy-hibernate3 -e 就能夠不運行hibernate3-maven-plugin插件,天然就不會衝突了,若是要用hibernate3-maven-plugin進行建表,那麼就改爲 <hibernate3.execute.phase>process-test-resources</hibernate3.execute.phase>maven