gpt4 book ai didi

java - 如何在代码中执行 osgi 命令

转载 作者:行者123 更新时间:2023-11-30 06:54:47 25 4
gpt4 key购买 nike

我正在使用 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 :

  1. BundleContext.installBundle 允许您从 URL 安装包

  2. 您可以找到一个带有 BundleContext 的 Bundle 实例。参见示例 BundleContext.getBundles()。在 Bundle 实例上,您可以调用 start()stop()update()卸载()

参见:BundleContextBundle

如果您真的想访问 shell 并执行命令,Equinox 使用 Apache Felix Gogo Shell。您应该获取对 CommandProcessor 的引用,从该处理器创建一个 CommandSession,然后在此 session 上调用 execute

@Reference
CommandProcessor commandProcessor;

...

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

关于java - 如何在代码中执行 osgi 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36017774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com