The API bundle
In OSGi, a service is described with an interface. This means that both service and client bundles of the same service have to share the same interface.
In order to decouple interface and implementation and be able to update a client bundle without impacting a service bundle, a good practice is to create an API bundle that contains just the interface.
We create this API bundle by just exposing the API package in the OSGi export package header as follows:
<osgi.export> org.apache.karaf.cellar.samples.dosgi.greeter.api*;version="${project.version}" </osgi.export>
The API bundle contains the interface that describes the Greeter service as follows:
package org.apache.karaf.cellar.samples.dosgi.greeter.api; /** * Interface describing the Greeter service. */ public interface Greeter { /** * Returns a greet message. * @return */ public GreetResponse greet(Greet greet); }
The service provides an operation: greet
corresponding to the greet()
method of the Greeter...