import org.osgi.framework.*;
public class MyBundleActivator implements BundleActivator {
private BundleContext bundleContext;
public void start(BundleContext context) throws Exception {
this.bundleContext = context;
ServiceReference<StartLevel> startLevelRef = bundleContext.getServiceReference(StartLevel.class);
StartLevel startLevel = bundleContext.getService(startLevelRef);
startLevel.setBundleStartLevel(context.getBundle(), 2);
MyService service = new MyServiceImpl();
bundleContext.registerService(MyService.class, service, null);
if (startLevel.getStartLevel() >= 3) {
}
}
public void stop(BundleContext context) throws Exception {
ServiceReference<MyService> serviceRef = bundleContext.getServiceReference(MyService.class);
MyService service = bundleContext.getService(serviceRef);
bundleContext.ungetService(serviceRef);
if (bundleContext.getBundle().getState() == Bundle.ACTIVE) {
}
}
}