LibraryLink ToToggle FramesPrintFeedback

Setting Up a FUSE ESB OSGi Project

A Maven project for building an OSGi bundle can be a simple single level project. It does not require any sub-projects. It does, however, require that you do the following:

  1. Add the bundle plug-in to your POM.

  2. Instruct Maven to package the results as an OSGi bundle.

[Tip]Tip

There are several Maven archetypes to set up your project with the appropriate settings.

A project that constructs an OSGi bundle can be a single level project. It only requires that you have a top-level POM file and a src folder. As in all Maven projects, you place all Java source code in the src/java folder. You place any non-Java resources into the src/resources folder.

Non-Java resources include Spring configuration files, JBI endpoint configuration files, WSDL contracts, etc.

[Note]Note

FUSE ESB OSGi projects that use FUSE Services Framework, FUSE Mediation Router, or another Spring configured bean also include a beans.xml file located in the src/resources/META-INF/spring folder.

Before you can use the bundle plug-in you must add a dependency on Apache Felix. After you add the dependency, you can add the bundle plug-in to the plug-in portion of the POM.

Example 7.1 shows the POM entries required to add the bundle plug-in to your project.

Example 7.1. Adding an OSGi Bundle Plug-in to a POM

...
<dependencies>
  <dependency> 1
    <groupId>org.apache.felix</groupId>
    <artifactId>org.osgi.core</artifactId>
    <version>1.0.0</version>
  </dependency>
...
</dependencies>
...
<build>
  <plugins>
    <plugin> 2
      <groupId>org.apache.felix</groupId>
      <artifactId>maven-bundle-plugin</artifactId>
      <configuration>
        <instructions>
          <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName> 3
          <Import-Package>*,org.apache.camel.osgi</Import-Package> 4
          <Private-Package>org.apache.servicemix.examples.camel</Private-Package> 5
        </instructions>
      </configuration> 
    </plugin>
  </plugins>
</build>
...

The entries in Example 7.1 do the following:

1

Adds the dependency on Apache Felix.

2

Adds the bundle plug-in to your project.

3

Configures the plug-in to use the project's artifact ID as the bundle's symbolic name.

4

Configures the plug-in to include all Java packages imported by the bundled classes and also import the org.apache.camel.osgi package.

5

Configures the plug-in to bundle the listed class, but not include them in the list of exported packages.

[Note]Note

You should edit the configuration to meet the requirements of your project.

For more information on configuring the bundle plug-in, see Configuring a Bundle Plug-in.

To instruct Maven to use the bundle plug-in, you instruct it to package the results of the project as a bundle. You do this by setting the POM file's packaging element to bundle.

There are several Maven archetypes to generate a project that is preconfigured to use the bundle plug-in:

The Spring OSGi archetype creates a generic project for building an OSGi project using Spring DM:

You invoke the archetype using the following command:

The FUSE Services Framework code-first archetype creates a project for building a service from Java:

You invoke the archetype using the following command:

The FUSE Services Framework wsdl-first archetype creates a project for creating a service from WSDL:

You invoke the archetype using the following command:

The FUSE Mediation Router archetype creates a project for building a route that is deployed into FUSE ESB:

You invoke the archetype using the following command: