从不同的插件访问资源包

Access resource bundle from different plugin

我有两个插件:

com.example.a
com.example.b

com.example.a 包含我想从 com.example.b 访问的 plugin.properties。 当我在插件 com.example.b 中调用以下内容时,我得到 MissingResourceException:

ResourceBundle resourceBundle = ResourceBundle.getBundle( "com.example.a",
                                                                Locale.getDefault() );
resourceBundle.getString( key );

这显然是错误的,但我希望你明白这一点。

如何从另一个插件访问属性文件的本地化字符串?

此代码将加载 plugin.properties 或在 'Bundle-Localization' MANIFEST.MF header:

中为插件指定的任何内容
Bundle bundle = Platform.getBundle("com.example.a");
BundleContext bundleContext = bundle.getBundleContext();
ServiceReference<BundleLocalization> ref = bundleContext.getServiceReference(BundleLocalization.class);
BundleLocalization bundleLoc = bundleContext.getService(ref);
ResourceBundle resourceBundle = bundleLoc.getLocalization(bundle, Locale.getDefault().toString());