I have been beating my head against the wall trying to get Apache POI to work within an OSGi bundle. Here is the history of what I have tried with no luck:
1) I initially tried using the pre wrapped Apache Servicemix POI bundle. However this had many dependencies I had to deploy, many of which were not needed. I hit a wall as even after adding Apache POI servicemix (and its dependencies), i was still getting issues with missing classes.
2) Due to the amount of unneeded stuff in the first solution, I decided to wrap up the dependencies inside a bundle. Basically I have a Blueprint service that acts as a wrapper for the POI functionality. All unit tests work fine but my pax exam tests were failing.
At first, it couldn't find classes that were dependencies (commons-codec,xmlbeans, etc). So I added the POI and POI OOMXL dependencies and all the other dependencies it needed. This solved most of the class loader issues. However this is the one I am currently stuck on. The bundle starts just fine, but once it hits a point where it tries create an excel workbook, it fails with the following stack trace:
java.lang.ClassNotFoundException: com.bea.xml.stream.EventFactory not found by org.ops4j.pax.exam.rbc [104]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1574)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:68)
at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:178)
at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
at javax.xml.stream.XMLEventFactory.newInstance(XMLEventFactory.java:30)
Here are the dependencies I am including:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${apache.poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${apache.poi.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.6.0</version>
</dependency>
It seems that the pax container cannot find the EventFactory. If anyone has any suggestions i would greatly appreciate the help.