Over a million developers have joined DZone.

How to register an OSGI service

Learn more about Kotlin, a new programming language designed to solve problems that software developers face every day brought to you in partnership with JetBrains.

  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>



The Java Zone is brought to you in partnership with JetBrains.  Discover how powerful static code analysis and ergonomic design make development not only productive but also an enjoyable experience.

Topics:

Published at DZone with permission of Achala Chathuranga Aponso , DZone MVB .

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}