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!
Join the DZone community and get the full member experience.
Join For FreeThe 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
Apache Maven installation.
JDK 1.7 or above.
Custom OSGI bundle to be deployed as system bundle.
Third-party installation to a local Maven repo.
Apache ServiceMix 7.0.0.M1 or above.
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.
Download Apache ServiceMix.
Extract the downloaded ZIP into a working directory.
Set the below variables in System’s Environment Variables:
KARAF_DEBUG=TRUE
.KARAF_HOME=<SERVICEMIX_HOME>
.
Edit
$KARAF_HOME/etc/org.ops4j.pax.url.mvn.cfg
to change the location of Maven’ssettings.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
.
Create the below Karaf system folder:
$KARAF_HOME/system/<groupid>/<artifactid>/<version>
. Example:
Paste the Maven-built framework.
Include this entry in
$KARAF_HOME/etc/startup.properties
:mvn\:com.test.base/my-framework/0.0.1-SNAPSHOT = 16
.
Start
$KARAF_HOME/bin/servicemix.bat
.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
.
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
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.
Opinions expressed by DZone contributors are their own.
Comments