Reputation: 722
I am trying to get image from a bundle in eclipse plugin project. But it always return null. Please find the project structure below. I want to get the URL of an image "icon_4.png" which is under "images/EmailTemplatesOutput/assets/icon_4.png". I have tried different ways. But it returns null.
String path = "icon_4.png";
Bundle bundle = Platform.getBundle("BulkDemo");
URL url = FileLocator.find(bundle, new org.eclipse.core.runtime.Path(path), null);
ImageDescriptor imageDesc = ImageDescriptor.createFromURL(url);
Image image = imageDesc.createImage();
Upvotes: 1
Views: 591
Reputation: 111142
Don't put the 'images' directory in the 'src' folder, put it at the top level of the project (like 'bin' and 'META-INF'). Make sure you update the 'build.properties' to include the images folder in the build.
The path for the image is relative to the plug-in root so it will be images/EmailTemplatesOutput/assests/icon_4.png
(assuming you move the images directory).
The URL returned by FileLocator.find
uses an Eclipse only scheme so can only be used by Eclipse APIs. You can convert the URL to a normal file URL by adding:
URL fileURL = FileLocator.toFileURL(url);
This may cause Eclipse to unpack your plug-in to a temporary location to access the files.
Upvotes: 1