OSGi 片段:修补 Eclipse 插件中的错误
在听说 OSGi 片段后,我想知道:
我可以使用片段来注入补丁,即替换现有的、签名包中的现有类吗?
有文档说明如何做到这一点吗?
After hearing about OSGi fragments, I was wondering:
Can I use a fragment to inject a patch, that is, replace an existing class in an existing, signed bundle?
Is there documentation how to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还没有使用过签名的包,但它们是一种让片段覆盖主机包中的类的方法。但是,您需要提前为此做好计划。
在你的主机包中定义一个包类路径:
Bundle-Classpath: jar-not-in-host.jar;。
该 jar 文件不应存在于主机中。然后您的片段可以包含一个名为 jar-not-in-host.jar 的 jar。当附加片段时,jar-not-in-host.jar 中的类将在主机包根目录中的类之前加载。
我知道不是很好,但它确实有效。
I haven't played around with signed bundles, but their is a way to get fragments to override classes in the host bundle. However you need to have planned for this ahead of time.
In your Host Bundle define a Bundle-Classpath thus:
Bundle-Classpath: jar-not-in-host.jar;.
This jar file should not exist in the host. Then your fragment can contain a jar called jar-not-in-host.jar. When the fragment is attached the classes in the jar-not-in-host.jar will be loaded before the classes in the root of the host bundle.
Not very nice I know, but it works.
答案是否。
OSGi 片段没有自己的类加载器,它们被视为主机的一部分。他们无法注入新代码来替换现有的类。 fragment 的常见用法是为不同的主机提供不同的实现。需要其功能的其他捆绑包(由主机捆绑包导出)将不依赖于具体实现。
Bundle 已经是 OSGi 的原子概念,如果你想修补某些东西,你应该提供它的更新版本。
The answer is no.
OSGi fragments don't have their own class loader and they are seen as part of the host. They can't inject the new code into replacing the existing class. The common usage of fragment is providing different implementations for different hosts. Another bundles who require its capability(exported by the host bundle) won't depend on the concrete implementation.
Bundle already is the atom concept of OSGi, you should provide newer version of it if you want to patch something.