问题
Given this scenario:
Bundle A: component 1A (enabled:false) Bundle B: component 2B
How can i enable component 1A from Bundle B or Component 2B?
I've tried to do it by using componentContext,
dsContext.enableComponent("1A");
but it seems to work only with services in the same bundle.
回答1:
Your using a mechanism that is intended for management and it seems you want to use it on application level. Declarative services should be enabled/disabled through their dependencies, or through a domain specific means. You should not let another actor that enables/disables a component. Using this route you likely get very complex systems since it is difficult to control the timing and order.
Technically, you should use the Apache Felix SCR Service to control the enable/disable of a DS, this is unfortunately not yet standardized and then requires Apache Felix SCR as implementation of DS.
If you explain why you want to enable/disable other components it might be possible to point you to better solutions.
来源:https://stackoverflow.com/questions/18982190/osgi-equinox-enable-component-from-external-bundle