NullPointerException org.apache.commons.digester.Digester.getXMLReader,Digester.java:1058

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.