项目集成了  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中加入以下配置:

   
   
   
   
  1. <profile> 
  2. <id>lazy-hibernate3id> 
  3. <properties><hibernate3.execute.phase>packagehibernate3.execute.phase>properties> 
  4. profile> 

然后在pom.xml 修改hibernate3-maven-plugin的执行阶段,修改如下:

   
   
   
   
  1. <plugin> 
  2.     <groupId>org.codehaus.mojogroupId> 
  3.     <artifactId>hibernate3-maven-pluginartifactId> 
  4.     <version>2.2version> 
  5.     <dependencies> 
  6.         <dependency> 
  7.          <groupId>${jdbc.groupId}groupId>    
  8.            <artifactId>${jdbc.artifactId}artifactId>    
  9.            <version>${jdbc.version}version>    
  10.         dependency> 
  11.     dependencies> 
  12.     <configuration> 
  13.         <components> 
  14.             <component> 
  15.                 <name>hbm2ddlname> 
  16.                 <implementation>annotationconfigurationimplementation> 
  17.             component> 
  18.         components> 
  19.         <componentProperties> 
  20.             <drop>truedrop> 
  21.             <jdk5>truejdk5> 
  22.             <propertyfile>target/classes/jdbc.propertiespropertyfile> 
  23.         componentProperties> 
  24.         <skip>${maven.test.skip}skip> 
  25.     configuration> 
  26.     <executions> 
  27.         <execution> 
  28.             <phase>${hibernate3.execute.phase}phase> 
  29.             <goals> 
  30.                 <goal>hbm2ddlgoal> 
  31.             goals> 
  32.         execution> 
  33.     executions> 
  34. plugin> 

注意红色字体部分。

然后再在pom.xml加入以下配置:

   
   
   
   
  1. <properties> 
  2.        <dbunit.dataTypeFactoryName>org.dbunit.ext.mysql.MySqlDataTypeFactorydbunit.dataTypeFactoryName> 
  3.        <dbunit.operation.type>CLEAN_INSERTdbunit.operation.type> 
  4.        <hibernate.dialect>org.hibernate.dialect.MySQL5InnoDBDialecthibernate.dialect> 
  5.        <jdbc.groupId>mysqljdbc.groupId> 
  6.     <jdbc.artifactId>mysql-connector-javajdbc.artifactId> 
  7.        <jdbc.version>5.1.13jdbc.version> 
  8.        <jdbc.driverClassName>com.mysql.jdbc.Driverjdbc.driverClassName> 
  9.        <jdbc.url>jdbc.url> 
  10.        <jdbc.username>rootjdbc.username> 
  11.        <jdbc.password>rootjdbc.password> 
  12.        <hibernate3.execute.phase>packagehibernate3.execute.phase> 
  13.   properties> 

注意 <hibernate3.execute.phase>packagehibernate3.execute.phase> 配置

以后输入mvn cobertura:cobertura -dPlazy-hibernate3 -e 就可以不运行hibernate3-maven-plugin插件,自然就不会冲突了,如果要用hibernate3-maven-plugin进行建表,那么就改成 <hibernate3.execute.phase>process-test-resourceshibernate3.execute.phase>