我正在使用Equinox。我想在代码中执行osgi命令。

例如安装捆绑包命令

public void start(BundleContext context) throws Exception {

    String cmd = "install file:///e://testBundle.jar"

    // How can I execute cmd in code?
    ...
}


感谢帮助

最佳答案

您可以通过BundleContext或Bundle的实例来管理bundle:


BundleContext.installBundle允许您从URL安装捆绑软件
您可以使用BundleContext找到一个Bundle实例。参见例如BundleContext.getBundles()。在Bundle实例上,可以调用start()stop()update()uninstall()


请参阅:BundleContextBundle

如果您确实要访问Shell并执行命令,则Equinox使用Apache Felix Gogo Shell。您应该获得对CommandProcessor的引用,从此处理器创建CommandSession,然后在此会话上调用execute

@Reference
CommandProcessor commandProcessor;

...

CommandSession commandSession = commandProcessor.createSession(System.in, System.out, System.err);
commandSession.execute("..");

09-11 19:20