Pregunta

For a project I'm trying to get Excel XML functionality using Apache POI to work with OSGI.

I've tried the POI ServiceMix bundle, but this was missing the ooxml-schemas jar. Adding the jar to the bundle and including it in the manifest didn't seem to work.

Then I tried to creating wrapper bundles for POI 3.10, but also to no avail. Same error.

Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl not found by org.apache.poi [8]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
... 105 more

Subsequent calls lead to the following:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument
at org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown Source)
at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:44)
... 93 more

XMLBeans is available as a bundle exporting all of its packages, and I've tried the ServiceMix bundle as well as making one out of the jar included with POI 3.10.

Could someone guide me through the process of creating a working OSGI bundle that can handle Excel 2007+ XML documents? Help much appreciated.

¿Fue útil?

Solución

The problem is that the classes from org.apache.poi.ooxml-schemas call Class.forName("org.apache.xmlbeans.impl.schema"), so you need an import of this package in the manifest of your ooxml-schemas bundle.

I solved it by adding <DynamicImport-Package>*</DynamicImport-Package> to the configuration of the maven-bundle-plugin when building the ooxml-schemas bundle.

Otros consejos

We use a bundle that merges poi, poi-ooxml and poi-ooxml-schemas to work around the class loading issue.

For that we use Gradle with bnd-platform. It allows building and adapting OSGi bundles based on Maven dependencies. Merging JARs to a combined bundle can also be done easily.

I set up an example build with an Apache POI bundle (and implicitly, its POM-defined dependencies) on GitHub. It's an excerpt from or own configuration for building the complete target platform for an OSGi based application.

You can clone it (sample-poi branch) and try it running ./gradlew clean bundles. Created bundles will be in build/plugins.

Caused by: java.lang.ClassNotFoundException:
  org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl
  not found by org.apache.poi [8]

This means that code within bundle org.apache.poi looks for class SchemaTypeSystemImpl of package org.apache.xmlbeans.impl.schema and can't find it. Given that both class and package look like implementation classes, I'd hypothesize that it's proper and correct that they aren't accessible outside their bundle.

Could you add the complete stack trace for the first exception, so that the call site of the Class.forName() will be visible? In all likelihood that's just the downstream of a configuration issue, but it will help narrow it down.

I was able to use the poi library in OSGi by adding the following bundles to the run bundles:
* org.apache.servicemix.bundles.poi
* org.apache.servicemix.bundles.xmlbeans
* commons-collections4
* commons-compress
* commons-math3
* Saxon DOM 8.9.0.4-osgi

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top