【问题标题】:Are externalised plugin.xml strings available to downstream plugins?下游插件是否可以使用外部化的 plugin.xml 字符串?
【发布时间】:2010-11-22 01:54:14
【问题描述】:
如果我有插件通用,插件 A 和 B 作为单独的插件/产品,两者都取决于插件通用。
在插件通用中,我将 plugin.xml 中的字符串外部化,这给了我 %bundle-vendor = "My Company Name"。
在下游插件 A 和 B 中,我可以使用常见的 bundle-vendor 属性作为 vendor.我尝试在公共插件 id 前面加上它,但它没有用。这应该可以吗?
【问题讨论】:
标签:
eclipse
eclipse-plugin
osgi
plugin.xml
【解决方案1】:
据我记得 plugin.properties 在插件之外不可用。但是,您可以定义一个属性类型(扩展 org.eclipse.osgi.util.NLS)来自动加载属性文件并将它们公开给其他插件。
类型中的每个静态字符串属性都将根据 NLS 规则从属性文件中处理并使其可用。
这是一个简单的示例,它将加载属性文件并在加载类时填充静态变量 some_property 和 some_other_property。
public class ContentMessages extends NLS {
private static final String BUNDLE_NAME =
"name.seller.rich.content.messages"; //$NON-NLS-1$
public static String some_property;
public static String some_other_property;
static {
// load message values from bundle file
reloadMessages();
}
public static void reloadMessages() {
NLS.initializeMessages(BUNDLE_NAME, ContentMessages.class);
}
}
【解决方案2】:
很好的答案里奇。我唯一要添加的是确保您在捆绑清单中公开包/类,以确保其他捆绑可以访问它。