package com.example.bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class MyBundleActivator implements BundleActivator {
public void start(BundleContext bundleContext) throws Exception {
}
public void stop(BundleContext bundleContext) throws Exception {
}
}
package com.example.bundle;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@Component
public class MyBundleComponent {
@Reference
private AnotherBundleService anotherBundleService;
@Activate
public void activate() {
anotherBundleService.doSomething();
}
}
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
public class BundleManager {
private BundleContext bundleContext;
public void installBundle(String location) {
Bundle bundle = bundleContext.installBundle(location);
bundle.start();
}
public void uninstallBundle(String symbolicName) {
for (Bundle bundle : bundleContext.getBundles()) {
if (bundle.getSymbolicName().equalsIgnoreCase(symbolicName)) {
bundle.uninstall();
break;
}
}
}
}