jaxb2(1.x)和selenium不兼容

jaxb2用来将schema转换为java代码,selenium是GUI自动化测试的lib。由于项目中需要同时支持这两个feature,所以一同配置在pom中:

 
    org.seleniumhq.selenium  
    selenium-java  
    2.48.2 
   

 
   
     
      org.codehaus.mojo  
      jaxb2-maven-plugin  
      1.5
       
         
          inbound-common-v12-xjc  
           
            xjc 
            
           
            target/generated-sources  
            com.xxx.data.v12.common  
            src/main/resources  
            bindings.xml  
            src/main/resources/xsd/ASP1.2  
            Inbound_Common.xsd,Inbound_FailureResponse.xsd, Inbound_OperationalHistory.xsd, Inbound_TotalResponse.xsd  
            true  
            target/.inboundcommonschema1XjcStaleFlag  
            false  
            UTF-8 
           
         
       
     
   

结果执行mvn clean install时报错:

[ERROR]
Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:1.5:xjc
(inbound-user-creation-v12-xjc) on project jcat-test-common: DTD factory class
org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl does not extend from
DTDDVFactory. -> [Help 1]

定位:

从报错看,是在执行jaxb时使用了错误的xerce包,由于项目先加入jaxb2,然后是selenium,所以应该是selenium引入的冲突。为了验证想法,使用mvn dependency:tree查看selenium的依赖库:

[INFO] +- org.seleniumhq.selenium:selenium-java:jar:2.46.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-chrome-driver:jar:2.46.0:compile
[INFO] |  |  \- org.seleniumhq.selenium:selenium-remote-driver:jar:2.46.0:compile
[INFO] |  |     +- cglib:cglib-nodep:jar:2.1_3:compile
[INFO] |  |     +- com.google.code.gson:gson:jar:2.3.1:compile
[INFO] |  |     +- org.seleniumhq.selenium:selenium-api:jar:2.46.0:compile
[INFO] |  |     \- com.google.guava:guava:jar:18.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-htmlunit-driver:jar:2.46.0:compile
[INFO] |  |  \- net.sourceforge.htmlunit:htmlunit:jar:2.17:compile
[INFO] |  |     +- xalan:xalan:jar:2.7.2:compile
[INFO] |  |     |  \- xalan:serializer:jar:2.7.2:compile
[INFO] |  |     +- org.apache.httpcomponents:httpmime:jar:4.4.1:compile
[INFO] |  |     +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.17:compile
[INFO] |  |     +- xerces:xercesImpl:jar:2.11.0:compile

解决:

在jaxb2 plugin中添加dependence:


... 
   
     
      xerces  
      xercesImpl  
      2.9.1 
      
     
      xalan  
      xalan  
      2.7.2 
     
   

再次执行mvn clean install,搞定!

你可能感兴趣的:(jaxb2(1.x)和selenium不兼容)