public interface HelloWorldService {
void sayHello();
}
public class HelloWorldServiceImpl implements HelloWorldService {
public void sayHello() {
System.out.println("Hello World!");
}
}
plain
Bundle-SymbolicName: com.example.bundle
Bundle-Version: 1.0.0
Bundle-Activator: com.example.bundle.Activator
Export-Package: com.example.service
Service-Component: OSGI-INF/helloworldservice.xml
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.example.service.helloworld">
<implementation class="com.example.bundle.HelloWorldServiceImpl"/>
<service>
<provide interface="com.example.service.HelloWorldService"/>
</service>
</scr:component>
ServiceReference reference = context.getServiceReference(HelloWorldService.class);
HelloWorldService service = (HelloWorldService) context.getService(reference);
service.sayHello();