Apache POI 5 and XMLBeans Classpath issues
Asked Answered
T

0

10

I tried answering on the following post, but I don't have the "reputation" and really do not have time to hunt down 10 questions to answer. Runtime Exception - POI 5 and xmlbeans

With POI 5 and XMLBeans 4 (or 5) in WebLogic server there is a classloader issue where it will try to use the underlying XMLBeans jar in the WebLogic server modules directory.

When packaging in an EAR you can use the weblogic-application.xml descriptor to override class loading with . However, listing the POI and dependencies packages here will result in further errors. The class SchemaTypeLoaderImpl is looking in the new (org.apache.xmlbeans.metadata) AND old (schemaorg_apache_xmlbeans) packages. So you should also include the old package in the override list.

Now SchemaTypeLoaderImpl also tries to load the TypeSystemHolder classes using ClassLoader.getResource before it tries to look it up with Class.forName. To fix this issue you need to prevent it from finding the old classes, as the previous package override is only giving your application bundled library priority over the underlying server libraries. It is not preventing it from finding these out of date classes and trying to load them as well. This can be done by using for these resources.

NOTE that I am only using basic XSSFWorkbook XLS functionality! You may need to track down other resources if you use other POI functionality.

For example the following weblogic-application.xml descriptor allows your application to use bundled POI/XMLBeans libraries and ignore the old resources.

<prefer-application-packages>
    <package-name>org.apache.commons.collections4.*</package-name>
    <package-name>org.apache.commons.compress.*</package-name>
    <package-name>org.apache.poi.*</package-name>
    <package-name>org.apache.xmlbeans.*</package-name>
    <package-name>org.openxmlformats.*</package-name>
    <package-name>schemaorg_apache_xmlbeans.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
    <resource-name>schemaorg_apache_xmlbeans/system/sXMLCONFIG/TypeSystemHolder.class</resource-name>
    <resource-name>schemaorg_apache_xmlbeans/system/sXMLLANG/TypeSystemHolder.class</resource-name>
    <resource-name>schemaorg_apache_xmlbeans/system/sXMLSCHEMA/TypeSystemHolder.class</resource-name>
    <resource-name>schemaorg_apache_xmlbeans/system/sXMLTOOLS/TypeSystemHolder.class</resource-name>
</prefer-application-resources>
Tatiana answered 29/4, 2021 at 0:1 Comment(1)
I'll probably release XmlBeans 5.0.1 soon and I don't have access to a WebLogic server. Any recommendations are welcomed. Although my goal was to be downward compatible, I think this isn't feasible anymore and I'm better off removing the old lookups.Se

© 2022 - 2024 — McMap. All rights reserved.