OSGi 片段:修补 Eclipse 插件中的错误

发布于 2024-10-08 18:13:48 字数 104 浏览 7 评论 0原文

在听说 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遇见了你 2024-10-15 18:13:48

我还没有使用过签名的包,但它们是一种让片段覆盖主机包中的类的方法。但是,您需要提前为此做好计划。

在你的主机包中定义一个包类路径:

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.

溺孤伤于心 2024-10-15 18:13:48

答案是

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文