如何在Eclipse中访问插件的成员文件和文件夹



我们有一个导出到RCP产品的插件。在插件中,有一个包含一些文件的文件夹。如何以编程方式访问Eclipse中某个文件夹下的插件文件?

使用org.eclipse.core.runtime.FileLocator类访问插件中的文件。

Bundle bundle = ... bundle containing the files
IPath path = new Path("relative path in plug-in of the file");
URL url = FileLocator.find(bundle, path, null);
URL fileUrl = FileLocator.toFileURL(url);

FileLocator.find方法返回的url使用Eclipse特定的方案,只能与特定的Eclipse api一起使用。

FileLocator.toFileURL调用将URL转换为正常的file URL,为了做到这一点,可能需要将插件jar解包到临时位置。

您可以使用

获取Bundle
Bundle bundle = FrameworkUtil.getBundle(getClass());

获取包含当前类的包或

Bundle bundle = Platform.getBundle("plugin id");

通过插件id访问包。

最新更新