簡體   English   中英

資源文件夾路徑問題

[英]Problems with path to resource folder

我的eclipse插件中有以下build.properties

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

我的plugin.xml是

<?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>
               .

以及項目的以下結構

在此處輸入圖片說明

當我嘗試使用以下代碼加載圖像時,出現空指針異常。

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

文件路徑看起來有些問題。 我檢查過,所有png文件都具有真實名稱,但是為什么以及如何修復它? 此致弗拉基米爾

您必須在build.propertiesbin.includes部分中包含resources文件夾。

通常將resources文件夾放在項目的頂層,而不是src文件夾中。 在這種情況下, build.properties將為:

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

您將在代碼中使用諸如resources/myimage.gif類的路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM