Example OSGi bundles and dependencies

November 14, 2023

Case 1: Introducing a new framework that has no link with the ones provided by Jahia

That means the framework(s) you are using are not extending one provided by Jahia as is, they are using some of them most probably but they are not adding or overriding any of those frameworks. 

In this case the integration should be straightforward, add your dependencies in your pom.xml file as usual. By default, your dependencies will be embedded in your bundle.

Then you need to configure the maven-bundle-plugin that will package your bundle into a jar, in this configuration you need to specify what package you want to export, and which dependencies you need to embed inside your bundle.

You can also decide to export some of your package, or packages provided by your dependency, by setting the export-package property :

<properties>
   <export-package>{local-packages}</export-package>
</properties>

The Export-Package instruction allows you to define the package you want to export to other bundle, those ones will be the only accessible class from another bundle. Here you can use the Maven macro ‘local-packages’ to define that you want to export all your packages and/or list them manually. This is needed if you want to expose some classes of the embedded framework. 

Case 2: Using Spring with Jahia

Using the Spring Framework in Jahia to declare services and wire them, is not recommended. OSGI built-in alternatives should be considered instead for that purpose. 

Spring does however provide a lot of other useful functionalities, and Jahia offers multiple ways to use it in bundles as any other third-party library.

  1. First of all, Jahia uses version 3.2.13 of the Spring Framework internally. Part of it is available to modules without specific effort. Because of this though, extra care to exclude this version has to be taken in order to be able to use a different one.
  2. The second option is to leverage the one provided as a Karaf feature with Jahia 8. This feature exposes Spring 5.1.9.RELEASE_1 as OSGI bundles. To make this work you will need to make sure that your module does not import any packages from a different version of Spring. A sample POM, from a module using the Spring feature, is available here: pom.xml
  3. The third option is to embed Spring artifacts inside your modules. To make this work you will need to make sure that your module does not import any packages from a different version of Spring. A sample POM, from a module using an embedded version of Spring, is available here: pom.xml

Be aware that options 2 and 3 are not compatible with modules using the capability mentioned in Services with the Spring Framework