简体   繁体   中英

Unable to get Image file URL from eclipse plugin project Bundle

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.

Project Structure is : 在此处输入图片说明

            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();

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM