6

My goal is to create an Excel 2007 document (XLSX) in an Eclipse RCP Environment (Excel 2003 is simple). I don't want to place the POI jars inside a /lib folder, instead I want to use a working POI OSGI bundle from my target definition.

All my attempts so far have failed to create a working OSGI bundle of POI 3.8. What I did so far:

  • I merged all relevant JAR files with the Ant zip task:

    • poi-3.8-beta3-20110606.jar
    • poi-ooxml-3.8-beta3-20110606.jar
    • poi-ooxml-schemas-3.8-beta3-20110606.jar
    • poi-scratchpad-3.8-beta3-20110606.jar
  • I ran the bnd tool with the wrap parameter: java -jar biz.aQute.bnd.jar wrap ./poi-3.8-beta3-20110606-merged.jar

  • I had to bundle the jars in the /ooxml-lib folder separately, with bnd:

    • xmlbeans-2.3.0.jar
    • stax-api-1.0.1.jar
    • dom4j-1.6.1.jar
  • This leads to ClassNotFoundExceptions for org.w3c.dom.Node because xmlbeans-2.3.0.jar exports four classes from this package org.w3c.dom. Normally the JavaSE-RuntimeEnvironment would export these.

  • I deleted the org/w3c/dom folder from xmlbeans-2.3.0.jar and rebundled the jar but I got other ClassNotFoundExceptions.

This is where I got so far. I think working with bnd wrap is not enough. Probably I must create a bnd.properties file and have explicit Export-Package/Import-Package statements but which work?

So, has anyone successfully managed to create a working POI 3.8 OSGI bundle?

aliopi
  • 3,682
  • 2
  • 29
  • 24

4 Answers4

5

If you don't need that specific version, simply use http://ebr.springsource.com/repository/app/bundle/version/detail?name=com.springsource.org.apache.poi&version=3.0.2.FINAL that page lists it's dependencies etc (which you can also download or reference if you're using Maven/Ivy)

May be http://engroup.sourceforge.net/maven2/engroup/osgi/commons/poi-osgi/3.1/ or http://ebr.springsource.com/repository/app/search?query=poi can provide some inspiration (in the first link there's a maven POM that lists the (bnd) instructions in the bundle plugin section).

Why are you merging the jars? Why not try wrapping each individually?

A second thing to try is to use existing OSGi'd jars of xmlbeans, stax-api and dom4j

Also you can configure what the JRE (system bundle) exports using "org.osgi.framework.system.packages" - so you can choose not to export org.w3c.dom

earcam
  • 6,662
  • 4
  • 37
  • 57
  • The problem with POI 3.0 is that it's missing all `ss` and `xssf` packages, which means it supports only Excel 2003 and not 2007. I'm merging the jars because when bundling them separately I got the dreaded `Package uses conflict` for the many conflicting `uses:=` OSGI directives. The jars stax-api & dom4j seem to be fine, but using another jar for xmlbeans (other than the one in the 3.8 dist) will not work because I think it contains some special generated classes which forbids me to use another one. I didn't expect this to be so complicated :( – aliopi Nov 09 '11 at 11:58
  • If you've only a single bundle that will be using POI then it may well be simpler to embed the lot in that bundle. I wouldn't disable the uses constaints. Another option is repeat this question on their email list(s) general@poi.apache.org – earcam Nov 09 '11 at 12:53
  • Yes, I could put the non-osgi jars in a lib folder but my initial goal was to do it cleanly, i.e in the target definition. I found a similar question for POI 3.7 in the [ServiceMix Forum](http://servicemix.396122.n5.nabble.com/Apache-Poi-3-7-component-td4912054.html) and even an official OSGI bundle for POI 3.6 [here](https://issues.apache.org/jira/browse/SMX4-511?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel), only it lacks what I need: OOXML support. – aliopi Nov 09 '11 at 15:34
1

I don't know about 3.8, but creating working OSGi bundle for 3.7 is quite easy with Bnd.

-classpath: poi-3.7-20101029.jar, 
  poi-ooxml-3.7-20101029.jar,
  poi-ooxml-schemas-3.7-20101029.jar, 
  poi-scratchpad-3.7-20101029.jar
Bundle-Name: Apache POI
Bundle-SymbolicName: org.apache.poi
Bundle-Version: 3.7.0
Bundle-ClassPath: .
Private-Package: *
Export-Package: org.apache.poi.*;-split-package:=merge-first
Import-Package: !org.openxmlformats.schemas*, \
  !schemasMicrosoftComOfficePowerpoint*, \
  !schemasMicrosoftComOfficeWord*, \
  junit*;resolution:=optional, \
  org.apache.commons.logging;resolution:=optional, \
  *
Include-Resource: @poi-3.7-20101029.jar, \
  @poi-ooxml-3.7-20101029.jar, \
  @poi-ooxml-schemas-3.7-20101029.jar, \
  @poi-scratchpad-3.7-20101029.jar
Jarek Przygódzki
  • 4,284
  • 2
  • 31
  • 41
1

If you are interested in a working example of the approach with BND, you can have a look at this project, providing a pom and a bnd file (inspired by Jarek's answer):

https://github.com/evandor/skysail-bundled-libraries/tree/master/skysail.bundles.poi

Running "mvn install" gives you an "OSGi-flavored" POI jar, which can be found as well here:

https://oss.sonatype.org/content/groups/public/de/twentyeleven/skysail/org.apache.poi-osgi/3.8/

You might have to play a bit with the bnd file to make it create the exact OSGi bundle you need (maybe you don't need all the dependencies, or you want to mark them as optional).

You will find all the documentation needed on the bnd homepage. I recommend starting with this page if you haven't used this great tool before.

evandor
  • 799
  • 1
  • 10
  • 23
1

I was able to do after some serious head banging. You can see the POM file over here:

http://servicemix.396122.n5.nabble.com/Apache-Poi-3-7-component-tc4912054.html#a5009396

I had to repackage XMLBeans 2.3.0 and embed in the bundle.

Cheers, Yogesh

Yogesh Chawla
  • 1,583
  • 18
  • 16