- 打开MANIFEST.MF,Extension Points标签页创建扩展点
- 扩展点ID输入一个短名(例如ep1,一般名字是复数,末尾会加s),以后查找的时候需要结合插件ID前缀(例如pluginid.ep1)
- 打开ep1.exsd,Definition标签页,然后参考其它定义了扩展点的插件来填写。一个例子:extension元素下只有一个sequence,该sequence上下界都是1,即只允许一个下级元素,该sequence下指定了其下级元素是ep1;ep1元素下有一个class属性,是java类型,实现了Interface1接口
- 同以前一样,在该扩展点上扩展功能,填写class属性,让它指向一个具体java类
- 像下面的代码那样调用扩展的功能:
IExtensionRegistry registry = Platform.getExtensionRegistry(); IExtensionPoint extension = registry.getExtensionPoint("pluginid.ep1"); assert extension != null; IConfigurationElement[] elements = extension.getConfigurationElements(); if (elements.length == 0) { throw new Exception("Failed to get pluginid.ep1 extension"); } Object obj = elements[0].createExecutableExtension("class"); assert obj instanceof Interface1; //TODO: 使用 obj
转载于:https://www.cnblogs.com/coxing/archive/2012/06/20/2555582.html