Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Deploy a Custom System Bundle

DZone's Guide to

How to Deploy a Custom System Bundle

A good developer will create their own framework to be extended by interface OSGI bundles for easy development and for code reusability. Customization is key!

· Integration Zone
Free Resource

Modernize your application architectures with microservices and APIs with best practices from this free virtual summit series. Brought to you in partnership with CA Technologies.

The intention of this blog is to give an idea to those (like me) who suffered from having no or little guidance when engineering an ESB. Before you decide how to start engineering your own ESB, decide on the right ESB tool. This blog makes use of Apache ServiceMix 7.0.0.M1 as an ESB tool, Apache maven 3.3.1 and Apache camel for development.

Prerequisites

Deploying Custom OSGI Bundle as System Bundle

Why use system bundle deployment? A good developer will create his or her own framework which offers features like constructors, security, error handling, database connectivity, third-party service connectivity, multithreading ability, clustering, high availability, extensibility, etc., to be extended by interface OSGI bundles for easy development and for code reusability. Apache ServiceMix activates bundles and context when deployed one in a deploy folder, but will do another if it's a system feature. The difference is that former deployments will be repetitive for each restart of ServiceMix/Karaf; the later method is just one-time.

The framework bundle shouldn't be restarted each and every time the ServiceMix starts. Otherwise, it isn't customized. A framework should be installed as a feature in ServiceMix only once and should be customized by interface bundles. Hence, a custom OSGI framework bundle should be deployed as system bundle.

Now, how do we deploy it as system bundle? Here are the steps.

  1. Download Apache ServiceMix.

  2. Extract the downloaded ZIP into a working directory.

  3. Set the below variables in System’s Environment Variables:

    • KARAF_DEBUG=TRUE.

    • KARAF_HOME=<SERVICEMIX_HOME>.

  4. Edit $KARAF_HOME/etc/org.ops4j.pax.url.mvn.cfg to change the location of Maven’s settings.xml as ServiceMix refers to Maven’s default local repository path ${user.home}/.m2/settings.xml.

    • Change the value of the config parameter org.ops4j.pax.url.mvn.settings=<M2_HOME>/conf/settings.xml. 

  5. Create the below Karaf system folder:

    •  $KARAF_HOME/system/<groupid>/<artifactid>/<version>Example:

  6. group id: com.test.base
    artifact id: my-framework
    version: 0.0.1-SNAPSHOT

    Folder structure to be created:

     $KARAF_HOME/system/com/test/base/my-framework/0.0.1-SNAPSHOT 

  7. Paste the Maven-built framework.

  8. Include this entry in $KARAF_HOME/etc/startup.properties: 

    • mvn\:com.test.base/my-framework/0.0.1-SNAPSHOT = 16.

  9. Start $KARAF_HOME/bin/servicemix.bat. 

  10. If any dependency of system bundle deployed throws an error, install those features. Examples:

    • features:addurl mvn:io.hawt/hawtio-karaf/1.2.3/xml/features.

    • features:install hawtio-core.

    • features:install camel-groovy.

That's it! Now, your preconfigured ESB is ready. You can create your interface that extends the OSGI system bundle and deploy it in ServiceMix for servicing requests.

The Integration Zone is proudly sponsored by CA Technologies. Learn from expert microservices and API presentations at the Modernizing Application Architectures Virtual Summit Series.

Topics:
esb ,apache servicemix ,maven ,bundles ,service requests ,integration ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}