NullPointerException org.apache.commons.digester.Digester.getXMLReader(Digester.java:1058)

本文介绍了如何使用Maven排除特定版本的依赖库以解决版本冲突问题,并提供了具体案例,如Apache CXF与不同版本的SAXParserFactory冲突的解决办法。

http://pwu-developer.blogspot.com/2010/01/nullpointerexception.html

Maven is great build tool making it easy to fetch all the library dependencies for a particular build. But what happens when you've got an application that uses wide variety of libraries of which can be dependent on the same library but different versions. Indeed we can have conflicts and the title of this blog is what I got as a result of some transitive dependency of Apache CXF.

The root cause of the above error is because an older version of the SAXParserFactory was being used. The class loaders for commons digester was using the SAXParserFactory from another JAR file in the classpath rather than the one provided in the JDK 1.6.
Others have had similar problems as in this forum

It turns out I had ther xercesImpl-2.6.2 in my classpath. This I needed to remove and boilied down to adding exclusions in my POM file as follows:

<!-- 
    ========================
    Apache CXF Web services
    ========================
    -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-bundle-minimal</artifactId>
        <version>2.2.4</version>
        
        <exclusions>
            <exclusion>
                <groupId>xalan</groupId>                
                <artifactId>xalan</artifactId>
            </exclusion>
            <exclusion>
                <groupId>xalan</groupId>                
                <artifactId>serializer</artifactId>
            </exclusion>

            <exclusion>
                <groupId>xom</groupId>
                <artifactId>xom</artifactId>
            </exclusion>        

            <exclusion>
                <groupId>xerces</groupId>
                <artifactId>xerces</artifactId>
            </exclusion>

            <exclusion>
                <groupId>xerces</groupId>
                <artifactId>xercesImpl</artifactId>
            </exclusion>

            <exclusion>
                <groupId>xerces</groupId>
                <artifactId>xmlParserAPIs</artifactId>
            </exclusion>
            
            <exclusion>
                <groupId>org.apache.santuario</groupId>
                <artifactId>xmlsec</artifactId>
            </exclusion>            
            
        </exclusions>        
        
    </dependency>  

---------------

maven 引入依赖时,会进行传递依赖也引入。

比如 a.jar 依赖 x.jar; b.jar 页依赖x.jar;

但是 a.jar依赖的是 x-1.1.jar; b.jar 依赖的是 x-1.0.jar;

这样的话,项目的就会同时引入了 x-1.1.jar 和 x-1.0.jar

这样的话,需要将 x-1.0.jar 进行排除出去;因为 a.jar 依赖x-1.1jar,但是因为同时存在 x-1.1.jar 和 x-1.0.jar 的话,a.jar 可能会使用x-1.0.jar而没有使用 x-1.1.jar;

这样可能会导致a.jar报错。所以需要将 x-1.0.jar 排除出去;

而 b.jar 依赖于 x-1.0.jar,因为 x-1.1.jar版本比 x-1.0.jar高,所以 b.jar使用 x-1.1.jar 和 使用 x-1.0.jar都应该没有问题;一般高版本会兼容低版本;

反过来就不行。

 

自己项目中删除掉 xerces-2.6.2.jar包就好了。

注意tomcat也要进行清理,不能仅仅在 eclipse 中删除,因为 删除了eclipse中项目中的jar包,tomcat中的可能并没有删除。所以需要进行 一下 clean.

 

转载于:https://www.cnblogs.com/digdeep/p/6419159.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值