java Eclipse扩展和声明性服务
我对Eclipse体系结构中的扩展/服务方法有点困惑。 开发者有两种选择:
- Eclipse插件扩展的使用http://www.eclipse.org/articles/Article-Plug-in-architecture/plugin_architecture.html
- 声明性服务的使用——http://www.eclipse.org/equinox/bundles/
你什么时候会使用其中一种,它的优点和缺点是什么 每种方法的优点是什么?还有,哪种方法更可取
# 1 楼答案
“当前”方法(pre3.5M5,与eclipse3.4类似)的问题在于,Eclipse插件扩展或OSGI DS(声明性服务)都需要一些特定于扩展或OSGI的API出现在插件中
我鼓励您在这个Powerpoint演示文稿中查看这篇关于声明性服务的精彩介绍:
Component Oriented Development in OSGi with Declarative Services, Spring Dynamic Modules and Apache iPOJO,来自2009年的日食
这里有一种味道:
模块层允许最小化静态依赖关系,更少的静态依赖关系意味着组件工作所需的东西
服务允许您的组件与其他组件交互
组件应该实现为POJO(普通的旧Java对象)与OSGi服务粘合在一起
声明性服务(DS)是OSGi概要第112节中的一个规范
它是在4.0版中引入的,基于扩展器模型
与所有扩展器一样,DS代表其他捆绑包执行任务。 DS规范定义了这个扩展器,它由框架实现
扩展包本身被称为服务组件运行时或SCR
术语DS和SCR有时会混淆:
DS是规范,SCR是实现规范的实际捆绑包
OSGi R4中的DS有显著的改进。2.
Equinox 3.5M5+支持其中许多更改
SCR(实现新的和改进的OSGi R4.2 DS-声明性服务-规范的“服务组件运行时”是一个“扩展包”)将:
你还有舱单。MF:
您将使用:
SCR将自动找到激活/停用方法
我们可以通过向XML声明添加属性来将它们称为其他名称
在R4之前。2.方法名无法更改,必须从DS API中获取类型为
ComponentContext
的参数。这破坏了组件的性能因此,不要编写“
BundleActivator
”(组件中OSGI特定的API:BAD),而是编写一个普通的POJO对象:您将简单地声明您对其他服务的引用:
您可以将组件作为服务本身发布:
这是通过XML描述符中的
<service>
元素完成的只需添加额外的
<provide>
元素即可提供多种服务使用
<property>
元素指定服务属性。这些属性被传递到激活中的组件,并发布到服务注册表# 2 楼答案
关于日食有一个很好的比较(我想是从2007年开始的:A Comparison of Eclipse Extensions and OSGi Services)
我会遵循你目标平台的惯例。因此,如果你正在为Eclipse3.4编写一个插件,比如说,创建一个Eclipse3.4插件(它将使用MANIFEST.MF作为依赖项,使用plugin.xml作为扩展/扩展点——你链接到的文章是针对Eclipse2.x的)。您可以检查插件目录的内容来确认这一点