Eclipse 扩展点与手动编程访问
要将一个插件公开的服务引用到另一个 Eclipse 插件中,我有两种方法
1.) 扩展点(复杂)
2.) 只需使用 BundleContext 获取捆绑包列表,然后访问其他 Eclipse 通过ServiceReference插件并调用相应的服务(非常简单)
我可以看到2比1容易得多。)
那么2是正确的方法吗?
为什么当时发明了1.)?
To reference services exposed by one plugin into another Eclipse Plugin I have two ways
1.)Extension Points (complicated)
2.)Just use BundleContext get List of Bundles and then access your other Eclipse
Plugin through ServiceReference and call respective services (very easy)
I can see that 2 is far more easier than 1.)
So is 2 the right way?
Why was 1.) invented then?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(1) 和 (2) 都不正确。
(1) 与 OSGi 服务无关。这是一个完全不同的用例。
(2) 你把事情搞得比必要的复杂得多。您只需使用声明式服务来获取对您要使用的服务的引用。不要转到发布服务的捆绑包,因为您不应该知道或关心哪个捆绑包是服务的来源。
Neither (1) nor (2) are correct.
(1) simply has nothing to do with OSGi Services. It's an entirely different use-case.
(2) you have made far more complicated than necessary. You just need to use Declarative Services to obtain a reference to the service that you want to use. Do NOT go to the bundle that publishes the service, because you shouldn't know or care which bundle is the source of the service.
您可以在此处找到扩展和 OSGi 服务的详细比较。没有对错之分(恕我直言,扩展点机制并不复杂,工具更好,...),在某些情况下,一个比另一个更好。 Eclipse 的早期版本并不基于 OSGi,因此 OSGi-way 自 Eclipse 3.0 起就可用。
You can find here a good comparison of extensions and OSGi-services. There is no right or wrong (IMHO the extension point mechanism is not complicated, the tooling is better,...), in some scenarios the one is better in some the other. Eclipse was in its early versions not based on OSGi so the OSGi-way is available since Eclipse 3.0.