Extracting the first OSGi bundle

The idea: Extract the core bundle from the pebble.war.

What to do first? Move the singleton PebbleContext to a core bundle

  • Create a new Eclipse bundle project <ctrl>+3 + pip
  • PebbleContext becomes an interface and the implementation moves to the core bundle

The first cut was the PebbleContext. Here the MANIFEST.MF of the first slice:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: net.sourceforge.pebble.core
Bundle-SymbolicName: net.sourceforge.pebble.core
Bundle-Version: 2.3.2.A
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package:
    net.sourceforge.pebble.core
Import-Package:
    org.apache.commons.logging;version="[1.1.1,1.2.0)"
Require-Bundle:
    org.springframework.beans

Inside the META-INF/spring folder a small configuration file exports the pebble context as OSGi service:

<bean id="pebbleContext" class="net.sourceforge.pebble.core.impl.PebbleContextImpl"
    p:webApplicationRoot="pebble/"
    p:configuration-ref="configuration" />

<bean id="configuration" class="net.sourceforge.pebble.core.Configuration"
    p:dataDirectory="${dataDirectory}"
    p:url="${url}"
    p:secureUrl="${secureUrl}"
    p:multiBlog="${multiBlog}"
    p:smtpHost="${smtpHost}"
    p:fileUploadSize="${fileUploadSize}"
    p:userThemesEnabled="${userThemesEnabled}"
    p:httpsWorkaroundEnabled="${httpsWorkaroundEnabled}" />

<!-- export as OSGi references -->
<osgi:service ref="pebbleContext" interface="net.sourceforge.pebble.core.PebbleContext" />

Now the pebble context is exposed as an OSGi service and can be referenced from other bundles:

<!-- pebble.core -->
<osgi:reference id="pebbleContext" interface="net.sourceforge.pebble.core.PebbleContext" />

This post is part of a series about an OSGi experiment: Migrate a monolith to a modular OSGi application architecture.

The Beginning of an OSGi Experiment

Building OSGi ready pebble with Maven

Third time it's a charm

▶︎ Extracting the first OSGi bundle

Extract the DAO layer

▷ ...


Header cover Photo by Matthew Henry from Burst