javamavenapache-poistaxjavax

Apache POI and XMLConstants Conflict


After adding the org.apache.poi poi-ooxml dependency to my project, I am now getting the following error:

javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI cannot be resolved or is not a field

When I try to view the source, there no longer is one, and eclipse is looking for the source in: .m2/repository/stax/stax-api/1.0.1/stax-api-1.0.1-sources.jar


Solution

  • poi-ooxml also imports stax-api, which contains a custom version of javax.xml.XMLConstants.

    My solution was to have Maven exclude this import in my pom file:

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.16</version>
        <exclusions>
            <exclusion>
                <groupId>stax</groupId>
                <artifactId>stax-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>