1

I'm currently trying to use apache POI to make excel files in java, SXSSF to be exact. When running it however, I'm getting the following error:

Caused By: java.lang.ExceptionInInitializerError
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl.build(SchemaTypeLoaderImpl.java:161)
        at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.<init>(SchemaTypeSystemImpl.java:198)
        at org.apache.xmlbeans.metadata.system.sXMLSCHEMA.TypeSystemHolder.<init>(TypeSystemHolder.java:9)
        Truncated. see log file for complete stacktrace
Caused By: org.apache.xmlbeans.XmlRuntimeException: java.lang.ClassCastException: org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl cannot be cast to org.apache.xmlbeans.SchemaTypeLoader
        at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl.build(SchemaTypeLoaderImpl.java:164)
        at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.<init>(SchemaTypeSystemImpl.java:198)
        at org.apache.xmlbeans.metadata.system.sXMLTOOLS.TypeSystemHolder.<init>(TypeSystemHolder.java:9)
        at org.apache.xmlbeans.metadata.system.sXMLTOOLS.TypeSystemHolder.<clinit>(TypeSystemHolder.java:6)
        at java.lang.Class.forName0(Native Method)
        Truncated. see log file for complete stacktrace
Caused By: java.lang.ClassCastException: org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl cannot be cast to org.apache.xmlbeans.SchemaTypeLoader
        at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl.build(SchemaTypeLoaderImpl.java:162)
        at org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.<init>(SchemaTypeSystemImpl.java:198)
        at org.apache.xmlbeans.metadata.system.sXMLTOOLS.TypeSystemHolder.<init>(TypeSystemHolder.java:9)
        at org.apache.xmlbeans.metadata.system.sXMLTOOLS.TypeSystemHolder.<clinit>(TypeSystemHolder.java:6)
        at java.lang.Class.forName0(Native Method)
        Truncated. see log file for complete stacktrace

Now, I know the similar issues to this have come up, and the usual fix is to alter weblogic.xml, and make

<prefer-web-inf-classes>false</prefer-web-inf-classes>

<wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.apache.commons.collections4.*</wls:package-name>
            <wls:package-name>org.apache.commons.compress.*</wls:package-name>
            <wls:package-name>org.apache.poi.*</wls:package-name>
            <wls:package-name>org.apache.xmlbeans.*</wls:package-name>
            <wls:package-name>org.apache.xmlbeans.XmlOptions</wls:package-name>
            <wls:package-name>org.openxmlformats.*</wls:package-name>
            <wls:package-name>schemaorg_apache_xmlbeans.*</wls:package-name>
        </wls:prefer-application-packages>
        <wls:prefer-application-resources>
            <wls:resource-name>schemaorg_apache_xmlbeans/system/sXMLCONFIG/TypeSystemHolder.class</wls:resource-name>
            <wls:resource-name>schemaorg_apache_xmlbeans/system/sXMLLANG/TypeSystemHolder.class</wls:resource-name>
            <wls:resource-name>schemaorg_apache_xmlbeans/system/sXMLSCHEMA/TypeSystemHolder.class</wls:resource-name>
            <wls:resource-name>schemaorg_apache_xmlbeans/system/sXMLTOOLS/TypeSystemHolder.class</wls:resource-name>
        </wls:prefer-application-resources>
    </wls:container-descriptor>
 

However, the issue arises that setting prefer-web-inf-classes to false breaks some of the rest of the application. So my question becomes, is there a way in the file I'm creating the excel, to specify that I want it to be built from the apache xmlbeans and not the weblogic xmlbeans? I'm thinking something like Classloader/Urlloader but I haven't been able to make that work properly yet, but I may be implementing it wrong.

Lastly, I'll include my pom.xml file

 <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>${org.apache.poi-version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.16.0</version>
        </dependency>

        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>${org.apache.commons-commons-codec-version}</version>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${org.apache.commons-commons-lang3-version}</version>
        </dependency>

        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.core</artifactId>
            <version>${org.eclipse.persistence-core-version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.10.14</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.3</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-to-slf4j</artifactId>
            <version>2.8.2</version>
        </dependency>
    </dependencies>
</project>
  • 1
    You might look at the _Component Map_ cited [here](https://stackoverflow.com/a/72839258/230513). – trashgod Jul 10 '22 at 18:40
  • schemaorg_apache_xmlbeans/system... is the location of the metadata before XmlBeans 5. So this says: take the classes of version 5, but lookup the metadata of the old XmlBeans (/POI) which comes with weblogic. what happens if you remove those 4 lines? – kiwiwings Jul 11 '22 at 05:41
  • Seems like removing those 4 lines doesn't change much. Leaving weblogic.xml as just false gives same result – bgarrett315 Jul 11 '22 at 13:05
  • @bgarrett315 Were you able to overcome this ? – DKG Dec 07 '22 at 06:58

1 Answers1

0

To be more specific, in my case I had added the following code to weblogic-application.xml for fixing the exception - java.lang.ClassCastException: org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl cannot be cast to org.apache.xmlbeans.SchemaTypeLoader

<weblogic-application>
    <prefer-application-packages>
        <package-name>org.apache.*</package-name>
        <package-name>schemaorg_apache_xmlbeans.*</package-name>
    </prefer-application-packages>
    <prefer-application-resources>
        <resource-name>schemaorg_apache_xmlbeans/*</resource-name>
    </prefer-application-resources>
</weblogic-application>
devwebcl
  • 2,866
  • 3
  • 27
  • 46
vsriram92
  • 593
  • 1
  • 4
  • 15