user1737519 user1737519 - 1 year ago 65
Java Question

OSGi Declarative Service (ds) usage

Right now I try to implement the services of my OSGi-application as ds.

Unfortunately I can't figure out how to access consume the service.

My Service looks like this:

public interface IService {
public void foo(<T> bar);

public class ServiceImpl implemets IService {
public void foo( bar){

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="" name="iservice">
<implementation class="ServiceImpl"/>
<provide interface="IService"/>

That's as far as I am right now.

But how can I access the service?

  1. I tried the following solution:

    But eclipse won't find the import for


  2. I also found this solution: h**p://

    But I'm a bit disappointed I'd have to wrap every single method and I'd have to use Eclipse specific apis

    There are the same problems with this solution: although the example uses the apache felix api and not the Eclipse api.

All I want to do is access/reference the service like this:

Iservice s = ???;<T> bar);

Thx for your help in advance!

P.S. sry for masking the links, but I can't include more than 2!

Answer Source

Here's a way to consume your service. I have invented a fictional Billing component that needs to call your IService. Instead of using the XML I am using bnd annotations, which are much more convenient:

public class Billing {

    private IService service;

    public void setService(IService service) {
        this.service = service;

    public void billCustomer() {
         // Do some stuff related to billing, whatever.

         // Blah blah blah

         // Now call the service, even though it wasn't real Java because
         // the <T> type parameter was unbound, but who cares...;

         // Yay.