Im using jdk22 and osgi 8.0.0
i have a jar with just one Interface called
public interface Person{
public void sayHi();
}
and I use it in two proyects, one of them where I have the Activator Class (bundle), here I created a service and registered throw BundleContext
public class Main implements BundleActivator {
@Override
public void start(BundleContext ctx) {
System.out.println("Hello world.");
Hashtable<String,String> map = new Hashtable<>();
map.put("key","value");
ctx.registerService(
Person.class,
new PersonImpl(),
map );
}
@Override
public void stop(BundleContext bundleContext) {
}
}
and Finally I have the proyect where comsume the bundle, here I created the BundleContext, installed and start the bundle, my problem happens because i can see the service when Iterate over getRegisteredServices() method
System.out.println(bundle.getRegisteredServices());
for(ServiceReference serviceReference: bundle.getRegisteredServices()) {
Person person = (Person) context.getService(serviceReference);
}
But when i try to get the ServiceReference it return me null
context.getServiceReference(Saludos.class);
what can i doing wrong ?
get the service reference from bundleContext.getServiceReference