RCP应用程序中不同元素的路径

问题描述:

我使用eclipse创建RCP应用程序,并且我无法加载图像,因为我不知道如何在生成的代码中找到它。我将尝试解释我的特定问题。RCP应用程序中不同元素的路径

注:该项目是一个游戏编辑器,它位于:http://chelder86.github.com/ArcadeTongame/

首先,这是项目结构:

enter image description here

下一个代码运行RCP应用程序正确地内Eclipse中,后changing the Working Workspace in the Eclipse Running Config.

package figures; 

(...) 

public class Sound extends ImageFigure { 

    public Sound() { 

     String picturePath = "src/figures/Sound48.png"; 
     // or String picturePath = "bin/figures/Sound48.png"; 

     Image image = new Image(null, picturePath); 
     this.setImage(image); 
    } 
} 

但当我创建产品并将其作为RCP应用程序导出时,它不起作用。我的意思是,RCP应用程序可以工作,但不会加载该映像。 注意:build.properties已检查图像。

我试着像这些不同的组合具有相同的结果:java.io.FileNotFoundException,则当我在Eclipse中运行它:

package figures; 
(...) 

public class Sound extends ImageFigure { 

    public Sound() { 

     String picturePath = getClass().getResource("Sound48.png").getPath(); 
     // or String picturePath = this.getClass().getClassLoader().getResource("bin/figures/Sound48.png").getPath(); 
     // or String picturePath = this.getClass().getClassLoader().getResource("figures/Sound48.png").getHost(); 
     // or similars 

     Image image = new Image(null, picturePath); 
     this.setImage(image); 
    } 
} 

我怎么能正确地加载它?

感谢您的帮助! :)

卡洛斯

+0

目前缺乏尼娅(图形DSL设计师)的文件,所以我在这里上传解决方案:http://estiloasertivo.blogspot.com.es/2013/02 /eugenia-epsilon-gmf-howto-use-images.html 谢谢阿列克谢! – chelder

尝试创建一个单独的“数字”文件夹旁边的“图标”文件夹。只放置图像文件,而不是.java文件。不要忘记将它添加到类路径和build.properties中。然后,这样的事情应该工作:

InputStream in = getClass().getResourceAsStream("figures/Sound48.png"); 
Image image = new Image(Display.getDefault(), in); 
+0

它完美的作品。感谢您分享您的知识! :) – chelder