简体   繁体   中英

Problems with path to resource folder

I have following build.properties in my eclipse plug-in

source.. = src/main/java,\
           src/main/resources
output.. = bin/
bin.includes = plugin.xml,\
               META-INF/,\

My plugin.xml is

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

 <extension
       point="org.eclipse.ui.decorators">
    <decorator
          adaptable="true"
          class="com.idc.xtext.shared.XtextFileDecorator"
          id="com.idc.xtext.shared.xtextFileDecorator"
          label="label"
          lightweight="false"
          location="REPLACE"
          objectClass="org.eclipse.core.resources.IFile"
          state="true">
    </decorator>
 </extension>
</plugin>
               .

And following structure of the project

enter image description here

When I try to load the image with following code, I have null pointer exception.

private static void putInIconMap(
            HashMap<String, Image> pIconsMap, String pEnv, String pIconPath) {
        ImageDescriptor fromPlugin = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID,
                        pIconPath);
        try {

            Image createImage = fromPlugin.createImage();
            pIconsMap.put(pEnv, createImage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

....

putInIconMap(dirsIconsMap, DEV, "icons/dev/Dirs_Dev_icon.png");

Look like some problem with the path to file. I have check, all png files have actual name But why and how I can to fix it? Regards, Vladimir

You must include the resources folder in the bin.includes section of your build.properties .

It is normal to put the resources folder at the top level of the project, not inside the src folder. In which case the build.properties would be:

source.. = src/main/java
output.. = bin/
bin.includes = plugin.xml,\
               META-INF/,\
               resources/,
               .

And you would use a path like resources/myimage.gif in your code.

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