java里Bundle是什么_java – 是否有类似于Eclipse片段项目的BundleActivator?

我正在构建一个Eclipse插件,它在常规插件项目中提供了一组核心功能.我通过片段项目提供的可选功能.但我需要片段在启动时使用主插件注册自己.

我不能在片段项目中拥有Bundle-Activator.所以我想知道是否有一些替代机制来声明我可以挂钩的入口点或某些回叫?

如果除了将片段项目转换为常规插件项目之外没有其他选择,那么我需要注意一个缺点吗?

这是我根据接受的答案使用的解决方案:

final IExtensionRegistry registry = Platform.getExtensionRegistry();

final IExtensionPoint extensionPoint = registry.getExtensionPoint("myextensionid");

final IExtension[] extensions = extensionPoint.getExtensions();

for (int j = 0; j < extensions.length; j)

{

final IConfigurationElement[] points = extensions[j].getConfigurationElements();

for (int i = 0; i < points.length; i)

{

if ("myelementname".equals(points[i].getName()))

{

try

{

final Object objImpl= points[i].createExecutableExtension("class");

objImplList.add(provider);

}

catch (CoreException e)

{

}

}

}

}

解决方法:

您可以定义扩展点并通过扩展查找/调用您的片段类.

IExtensionRegistry registry = Platform.getExtensionRegistry();

IExtensionPoint extensionPoint = registry

.getExtensionPoint("myplugin.myextension");

IConfigurationElement points[] = extensionPoint

.getConfigurationElements();

for (IConfigurationElement point : points) {

if ("myextensionFactory".equals(point.getName())) {

Object impl = point.createExecutableExtension("class");

if (impl instanceof IMyExtension) {

((IMyExtension) impl).foo();

}

}

}

}

编辑:

To use this approach I have to convert

my fragments projects to plug-in

projects. – bmatthews68

你不应该这样做.例如,在我的测试代码中,我在主机插件中有以下文件:

META-INF / MANIFEST.MF:

Manifest-Version: 1.0

Bundle-ManifestVersion: 2

Bundle-Name: Myplugin Plug-in

Bundle-SymbolicName: myplugin;singleton:=true

Bundle-Version: 1.0.0

Bundle-Activator: myplugin.Activator

Require-Bundle: org.eclipse.core.runtime

Eclipse-LazyStart: true

Export-Package: myplugin

plugin.xml中:

schema="schema/myextension.exsd" />

该片段包含以下文件:

META-INF / MANIFEST.MF:

Manifest-Version: 1.0

Bundle-ManifestVersion: 2

Bundle-Name: Myfragment Fragment

Bundle-SymbolicName: myfragment;singleton:=true

Bundle-Version: 1.0.0

Fragment-Host: myplugin;bundle-version="1.0.0"

fragment.xml之:

point="myplugin.myextension">

class="myfragment.MyExtension1">

这些项目是使用Eclipse 3.3.1.1生成的.来源:http://www.icode9.com/content-1-228351.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值