Over a million developers have joined DZone.

How to register an OSGI service

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

  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>



Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Published at DZone with permission of Achala Chathuranga Aponso, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}