package com.example.module1;
import org.springframework.osgi.extensions.annotation.Service;
@Service
public class MyModule implements Module {
}
package com.example.module2;
import org.osgi.framework.BundleContext;
import org.springframework.osgi.context.BundleContextAware;
public class MyModule2 implements BundleContextAware {
private BundleContext bundleContext;
public void setBundleContext(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
public void doSomething() {
// ...
Module module1 = (Module) bundleContext.getServiceReference(Module.class.getName());
module1.doSomething();
}
}
package com.example;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
public class ModuleLoader {
private BundleContext bundleContext;
public void setBundleContext(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
public void loadModule(String modulePath) throws BundleException {
Bundle bundle = bundleContext.installBundle(modulePath);
bundle.start();
}
}