import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
public class MyActivator implements BundleActivator {
private ServiceTracker<MyService, MyService> serviceTracker;
public void start(BundleContext bundleContext) throws Exception {
serviceTracker = new ServiceTracker<>(bundleContext, MyService.class, null);
serviceTracker.open();
MyService myService = serviceTracker.getService();
if (myService != null) {
}
}
public void stop(BundleContext bundleContext) throws Exception {
if (serviceTracker != null) {
serviceTracker.close();
serviceTracker = null;
}
}
}
Bundle-Activator: com.example.MyActivator
Import-Package: org.osgi.framework,
org.osgi.util.tracker