Search code examples
javajbossapache-poiwildfly

JBOSS Only Error: java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.ooxml.util.DocumentHelper


When using Apache POI to create a Workbook object to process an input stream, I started receiving the error:

java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.ooxml.util.DocumentHelper

I stepped through and found it occurring on this first line of code in this snippet from the ContentTypeManager.class (from org.apache.poi.openxml4j.opc.internal):

private void parseContentTypesFile(InputStream in) throws InvalidFormatException {
    try {
        Document xmlContentTypetDoc = DocumentHelper.readDocument(in);
        NodeList defaultTypes = xmlContentTypetDoc.getDocumentElement().getElementsByTagNameNS("http://schemas.openxmlformats.org/package/2006/content-types", "Default");
        int defaultTypeCount = defaultTypes.getLength();
        ....

So that line DocumentHelper.readDocument(in) is using the javax.xml.parsers.DocumentBuilder and that is where the issue ultimately is, it is unable to create a DocumentBuilder. I tried removing xercesImpl with no effect.

    <dependency>
        <groupId>xerces</groupId>
        <artifactId>xercesImpl</artifactId>
        <version>2.12.1</version>
    </dependency>

The code runs successfully using a WildFly server, but fails under JBOSS. We are moving to WildFly but in the meantime production still is running JBOSS.

Any thoughts on how to resolve the error? The project also has tika-core and tika-parsers-standard-package dependencies and not sure if those are causing an issue under JBOSS. Previously this had been working under JBOSS.

Update: My POM has these entries that are connected to issue:

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>5.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>5.2.2</version>
    </dependency>
    <dependency>
        <groupId>xerces</groupId>
        <artifactId>xercesImpl</artifactId>
        <version>2.12.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tika</groupId>
        <artifactId>tika-core</artifactId>
        <version>2.7.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tika</groupId>
        <artifactId>tika-parsers-standard-package</artifactId>
        <version>2.7.0</version>
    </dependency>

Solution

  • So I figured out the issue and wanted to follow-up. In order to get the apps running under WildFly and I had to add some logging exclusions because with WildFly there are already loggers on the classpath that cause conflicts. However, when running in JBOSS all parts of the application worked apparently except for POI because DocumentBuilder couldn't find the needed logging dependency on the classpath. Once I reverted the logging exclusions in the POM for JBOSS, it resolved the issue.