I think it's maybe your consumer bundle block the bundleActive thread
here my code and it worked

//common bundle

public interface IService {

}

//consumer bundle
public class Activator implements BundleActivator {
        
        public void start(final BundleContext bundleContext) throws Exception {
                
                new Thread(new Runnable() { //do not block active thread 
                        @Override
                        public void run() {
                                while (true) {
                                        final ServiceReference<IService> ref =
bundleContext.getServiceReference(IService.class);
                                        if (ref == null) {
                                                System.err.println("refer is 
null");
                                        } else {
                                                System.out.println("get 
service");
                                                break;
                                        }

                                }
                        }

                }).start();
        }
        public void stop(BundleContext bundleContext) throws Exception {
        }

}

//provider bundle
public class Activator implements BundleActivator {

        private static BundleContext context;

        static BundleContext getContext() {
                return context;
        }
        
        public void start(BundleContext bundleContext) throws Exception {
                Activator.context = bundleContext;
                bundleContext.registerService(IService.class.getName(), new 
IService() {
                }, null);
        }
        
        public void stop(BundleContext bundleContext) throws Exception {
                Activator.context = null;
        }

}

--
View this message in context: 
http://karaf.922171.n3.nabble.com/service-reference-is-null-after-service-reinstall-tp3996874p4008020.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Reply via email to