Platinum Partner
java,osgi,enterprise-integration,tips and tricks

How to register an OSGI service

  For this , I will use a code segment from wso2 appfactory.

The necessary code should be written inside the activate method which usually resides inside 'internal' package

protected void activate(ComponentContext context) {
BundleContext bundleContext = context.getBundleContext();
try {
MavenBuildDriver driver = new MavenBuildDriver();
bundleContext.registerService(BuildDriver.class.getName(), driver, null);
if (log.isDebugEnabled()) {
log.debug("Appfactory common bundle is activated");
}
} catch (Throwable e) {
log.error("Error in creating appfactory configuration", e);
}
}

In the above code BuildDriver is the interface.
the driver is an object of the class which implements the BuildDriver interface.

The content inside internal is not exposed. refer the pom.xml

<Private-Package>                    
org.wso2.carbon.appfactory.maven.build.internal.*,         
org.wso2.carbon.appfactory.jenkins.build.internal.*
</Private-Package>



Published at DZone with permission of {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

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

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}