这与Path for image file in Eclipse src folder, on a Mac问题类似,我正在使用
import org.eclipse.swt.graphics.Image;
public class Images {
static Image ICON_Search = new Image(App2.display, "src//search.jpg");
static Image ICON_RightArrow = new Image(App2.display, "src//right2.gif");
static Image ICON_LeftArrow = new Image(App2.display, "src//left4.gif");
static Image Background_White=new Image(App2.display,"src//whitebg.png");
}
我的所有图像都在项目的src文件夹中。这在Windows上工作正常,但是当我将其导出为jar并在MAC OS上运行时,它会引发File not found异常。
答案 0 :(得分:0)
src文件夹不会导出到Jar文件中。这只是为你的IDE源代码。您需要将图像作为资源加载:
Image image = new Image(App2.display,this.getClass().getResourceAsStream("search.jpg"));