Reputation: 137
We have a plug-in that is exported to an RCP product. In the plug-in, there is a folder that has some files. How can I access the plug-in files under a certain folder in Eclipse programatically?
Upvotes: 0
Views: 409
Reputation: 111142
Use the org.eclipse.core.runtime.FileLocator
class to access files in a plugin.
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);
The url
returned by the FileLocator.find
method uses an Eclipse specific scheme and can only be used with certain Eclipse APIs.
The FileLocator.toFileURL
call converts the URL to a normal file
URL, it may be necessary to unpack the plug-in jar to a temporary location in order to do this.
You can get the Bundle
using
Bundle bundle = FrameworkUtil.getBundle(getClass());
which gets the bundle containing the current class or
Bundle bundle = Platform.getBundle("plugin id");
to access a bundle by plug-in id.
Upvotes: 4