[英]Osgi: update already installed bundle when installing from jar?
I implemented a feature that my osgi is installing bundles that are represented as jars on the filesystem programmatically when starting or when receiving a new one. 我实现了一项功能,即我的osgi在启动时或在接收新的捆绑包时以编程方式在文件系统上安装表示为jar的捆绑包。 However, when I receive one, that already has been installed during start-up it crashes due to the conflict. 但是,当我收到一个时,它在启动过程中已经安装,由于冲突而崩溃。 Is there a way (I don't know the ID nor the name) in case of conflict to update instead of install programmatically? 如果发生冲突而不是通过编程安装,是否有办法(我不知道ID或名称)?
BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
Bundle bundle = context.getBundle("file:/Path.jar");
Hope somebody knows... 希望有人知道...
What I did in a similar case: 我在类似情况下的操作:
In case you want to allow multiple versions of the same bundle you can check also the version of the bundle before updating or installing. 如果要允许同一捆绑包的多个版本,则可以在更新或安装之前也检查捆绑包的版本。 In this case I would do the update if 在这种情况下,如果
If you care about the location and it is changed, instead of update(inputstream) use a bundle.uninstall() and bundlecontext.install(...) which reinstalls the bundle. 如果您关心位置并且位置已更改,请使用bundle.uninstall()和bundlecontext.install(...)代替update(inputstream),它们会重新安装捆绑包。
On the end you should call refresh() to have the correct package wirings. 最后,您应该调用refresh()以具有正确的包装接线。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.