美文网首页我爱编程
jaxb2(1.x)和selenium不兼容

jaxb2(1.x)和selenium不兼容

作者: Williamzzl | 来源:发表于2016-09-21 11:12 被阅读0次

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

    <dependencies>​ 
      <dependency> 
        <groupId>org.seleniumhq.selenium</groupId>  
        <artifactId>selenium-java</artifactId>  
        <version>2.48.2</version> 
      </dependency> 
    </dependencies>
    <build> 
      <plugins> 
        <plugin> 
          <groupId>org.codehaus.mojo</groupId>  
          <artifactId>jaxb2-maven-plugin</artifactId>  
          <version>1.5</version>
          <executions> 
            <execution> 
              <id>inbound-common-v12-xjc</id>  
              <goals> 
                <goal>xjc</goal> 
              </goals>  
              <configuration> 
                <outputDirectory>target/generated-sources</outputDirectory>  
                <packageName>com.xxx.data.v12.common</packageName>  
                <bindingDirectory>src/main/resources</bindingDirectory>  
                <bindingFiles>bindings.xml</bindingFiles>  
                <schemaDirectory>src/main/resources/xsd/ASP1.2</schemaDirectory>  
                <schemaFiles>Inbound_Common.xsd,Inbound_FailureResponse.xsd, Inbound_OperationalHistory.xsd, Inbound_TotalResponse.xsd</schemaFiles>  
                <extension>true</extension>  
                <staleFile>target/.inboundcommonschema1XjcStaleFlag</staleFile>  
                <clearOutputDir>false</clearOutputDir>  
                <encoding>UTF-8</encoding> 
              </configuration> 
            </execution> 
          </executions> 
        </plugin> 
      </plugins> 
    </build>
    

    结果执行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:

    <plugin>
    ... 
      <dependencies> 
        <dependency> 
          <groupId>xerces</groupId>  
          <artifactId>xercesImpl</artifactId>  
          <version>2.9.1</version> 
        </dependency>  
        <dependency> 
          <groupId>xalan</groupId>  
          <artifactId>xalan</artifactId>  
          <version>2.7.2</version> 
        </dependency> 
      </dependencies> 
    </plugin>
    

    再次执行mvn clean install,搞定!

    相关文章

      网友评论

        本文标题:jaxb2(1.x)和selenium不兼容

        本文链接:https://www.haomeiwen.com/subject/jxhaettx.html