LibraryLink ToToggle FramesPrintFeedback

Packaging Routes in a Bundle

This section explains how to modify an existing Maven project for a Apache Camel application, so that the project generates an OSGi bundle suitable for deployment in the Fuse ESB OSGi container. To convert the Maven project, you need to modify the project POM file.

To configure a Maven POM file to generate a bundle, there are essentially two changes you need to make: change the POM's package type to bundle; and add the Maven bundle plug-in to your POM. For details, see Modifying an Existing Maven Project.

In addition to the basic POM changes required for a generating bundle, Apache Camel requires you to customize the instructions for importing packages in the maven-bundle-plugin configuration. The Apache Camel application has an implicit dependency on the org.apache.camel.osgi package and this dependency must be declared using the Import-Package element.

For example, the following sample POM file shows how to define the Import-Package element in the instructions for the Maven bundle plug-in:

<project ...>


Where the Import-Package element contains the instructions that determine which Java packages are imported by the bundle. The wildcard, *, instructs the Maven bundle plug-in to import all of the packages explicitly referenced by the current bundle code and the explicitly listed org.apache.camel.osgi package is then added to the calculated list of packages.

There are two kinds of file that you can use to configure your project:

If you decide to use the blueprint configuration, you can embed camelContext elements in the blueprint file, as described in Blueprint configuration file.

If you decide to configure your Apache Camel application using blueprint, you must ensure that the camel-blueprint feature is installed (it is not installed by default). If necessary, install it by entering the following console command:

karaf@root> features:install camel-blueprint

The OSGi Configuration Admin service defines a mechanism for passing configuration settings to an OSGi bundle. You do not have to use this service for configuration, but it is typically the most convenient way of configuring bundle applications. Spring DM provides support for OSGi configuration, enabling you to substitute variables in a Spring XML file using values obtained from the OSGi Configuration Admin service.

Example 6.1 shows how to pass the value of the prefix variable to the constructor of the MyTransform bean, where the value of prefix can be set by the OSGi Configuration Admin service:

The syntax, ${prefix}, substitutes the value of the prefix variable into the Spring XML file. The OSGi properties are set up using the following XML elements:


To integrate Spring properties with the properties from the OSGi Configuration Admin service, insert an osgix:cm-properties element into the Spring XML file. This element creates a bean that gets injected with all of the properties from the OSGi ManagedService instance that is identified by the persistent-id attribute. The minimal configuration consists of an empty osgix:cm-properties element that sets the persistent-id attribute and the id attribute—for example:

<osgix:cm-properties id="preProps" persistent-id="org.fusesource.example"/>

For an example of how the persistent ID relates to OSGi configuration settings, see the example in Add OSGi configurations to the feature.

If you want to define defaults for some of the properties in the Spring XML file, add prop elements as children of the osgix:cm-properties element, as shown in Example 6.1.


Property placeholder is a Spring mechanism that enables you to use the syntax, ${PropName}, to substitute variables in a Spring XML file. By defining a ctx:property-placeholder element with a reference to the preProps bean (as in Example 6.1), you enable the property placeholder mechanism to substitute any of the variables from the preProps bean (which encapsulates the OSGi configuration properties) into the Spring XML file.