Adding OSGi Capabilities to a Web Service - 8.0

Talend ESB Development Guide

English (United States)
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Talend ESB
Talend Runtime
Design and Development

This chapter shows how to configure a Mavenized web service as an OSGi bundle in Talend ESB, an OSGi container based on Apache Karaf. For more information about Talend ESB, Karaf, and OSGi, please see the Talend ESB Container Administration Guide.

Let's package the java_first_jaxws web service created in the previous section as an OSGi bundle. We'll configure an Apache Felix plugin in Maven for this. For more information about Felix, please visit; for more information on using Felix with Maven, please refer to

In order to package the application as a bundle, first we need to add the Felix Maven dependency to the pom.xml created in the previous section:


Also, we'll need to add the Felix plugin used for creating the bundle. Create a new plugins element under the project's build element (not the build / pluginManagement / plugins element, that is used for configuration outside of Maven's default build process) and add:


Since we want to package as an OSGi bundle, also change the packaging element at the top of the pom file from war to bundle. As shown above in Felix's maven-bundle-plugin configuration com.talend.cxf.example.javafirst is exported as the bundle name and a CXF dependency is listed. In addition, the "Bundle-Activator" implementation is given. For bundle activation, we'll start and stop our service in the Activator's start and stop services respectively. Place the following class within the java_first_jaxws project:

package com.talend.cxf.example.javafirst;

import org.osgi.framework.BundleActivator; 
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator {
  private Endpoint endpoint;

  public void start(BundleContext arg0) throws Exception {
    try {
      HelloWorldImpl implementor = new HelloWorldImpl();
      String address = "http://localhost:9000/helloWorld";
      endpoint = Endpoint.publish(address, implementor);
      System.out.println("Server is started...");
    } catch (Exception e) {
      e.printStackTrace(); throw e;

  public void stop(BundleContext arg0) throws Exception {
    try {
    } catch (Exception e) {
      throw e;

All changes needed have been made. Now let's have Maven create the package:

Select the Run As > Maven Clean and then Run As > Maven Install from the popup menu on pom.xml, or alternatively, mvn clean install from a command prompt located in the project home directory. The application will be packaged and installed into your Maven local repository, by default located in your hidden <user home>/.m2 directory or otherwise as configured by the localRepository field in your ${Maven_HOME}/conf/settings.xml file. You should find it under ${MavenRepository}/ com/talend/cxf/example/ java_first_jaxws/0.0.1-SNAPSHOT/ java_first_jaxws-0.0.1-SNAPSHOT.jar.

We're now ready to deploy the bundle, which can be done as described in Deploying the WSP to Talend ESB (OSGi) except with an install command of:

install mvn:com.talend.cxf.example/java_first_jaxws/0.0.1-SNAPSHOT

Run the list command to make sure the bundle has started (check the logfiles in container/log folder for any errors if not) and ensure you can see the service WSDL at http://localhost:9000/helloWorld?wsdl. If so, we're ready to make SOAP calls to the service using soapUI as shown in the next section.