Java 如何在代码中执行osgi命令

Java 如何在代码中执行osgi命令,java,eclipse-plugin,osgi,equinox,Java,Eclipse Plugin,Osgi,Equinox,我用的是春分。我想用代码执行osgi命令 例如,安装bundle命令 public void start(BundleContext context) throws Exception { String cmd = "install file:///e://testBundle.jar" // How can I execute cmd in code? ... } 感谢您的帮助您可以通过BundleContext或捆绑包的实例管理捆绑包: BundleContex

我用的是春分。我想用代码执行osgi命令

例如,安装bundle命令

public void start(BundleContext context) throws Exception {

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

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

感谢您的帮助

您可以通过BundleContext或捆绑包的实例管理捆绑包:

  • BundleContext.installBundle
    允许您从URL安装捆绑包

  • 您可以找到一个带有BundleContext的
    Bundle
    实例。请参见示例
    BundleContext.getBundles()
    。在
    捆绑包
    实例上,可以调用
    start()
    stop()
    update()
    uninstall()

  • 见:和

    如果您确实想访问shell并执行命令,Equinox将使用ApacheFelixGogoshell。您应该获取对
    CommandProcessor
    的引用,从此处理器创建
    CommandSession
    ,并在此会话上调用
    execute

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

    您是希望执行命令来安装捆绑包,还是对任何命令更感兴趣?在osgi中安装/更新捆绑包很容易,您不必依赖命令即可完成此操作。我知道如何在osgi中安装捆绑包,但我希望在代码中动态执行start/stop/install/remove命令。谢谢。BundleContext.installBundle有效。但CommandProcessor无法导入。若要访问
    CommandProcessor
    CommandSession
    ,请将依赖项添加到组:“org.apache.felix”,名称:“org.apache.felix.gogo.runtime”。