Creating an Extension Bundle for a 3rd party library.

Question

How can we load a 3rd party library that is not an OSGi bundle.

Answer

One option to load a 3rd party library that is not an OSGi bundle is to create an extension/fragment bundle.

This can be done from the command line as follows. Lets say we have a 3rdparty.jar which contains packages under com.3rdparty.libs that need to be exported.

  • Add the jar to the shared classpath of your application server, for example crx-quickstart/server/lib/container under CQSE.
  • Create manifest file. For this example we will call it ext.mf. The file have the following contents:
    Bundle-ManifestVersion: 2 
    Bundle-SymbolicName: com.3rdparty.extension 
    Bundle-Version: 1.0
    Fragment-Host: system.bundle; extension:=framework 
    Bundle-Name: H2 JDBC Driver Extension 
    Bundle-Description: Bundle exporting com.3rdparty.libs 
    Export-Package: com.3rdparty.libs 
    
    
    Note that the blank line at the end of a jar manifest file is required. Also, all packages you need to export have to be explicitly added to Export-Package as a comma separated list
  • Create a jar file with above manifest using the following command.
    jar -cfm com.3rdparty.extension-1.0.jar ext.mf 
    
  • Install com.3rdparty.extension-1.0.jar using Felix Console or place it in the install folder of your CQ application. This should add org.h2 package to the export list of the System Bundle.
  • Please refer to section 3.15, Extension Bundles, of the OSGi Service Platform Core for more information about Extension Bundles.