import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class MyBundleActivator implements BundleActivator {
public void start(BundleContext context) throws Exception {
System.out.println("Bundle Started");
}
public void stop(BundleContext context) throws Exception {
System.out.println("Bundle Stopped");
}
}
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
public class MyServiceConsumer {
private BundleContext context;
public void start() {
ServiceReference serviceRef = context.getServiceReference(MyService.class.getName());
MyService myService = (MyService) context.getService(serviceRef);
myService.doSomething();
}
public void stop() {
context.ungetService(serviceRef);
}
}