【发布时间】:2012-12-31 18:12:02
【问题描述】:
我的第一个问题:
这几天我一直在尝试解决这个问题,但我到了失去耐心的地步。 以下是一些代码和我的项目结构。
问题:我怎样才能让getResources() 在 eclipse 中工作并在被导入到 jar 之后?
感谢您的帮助。
public enum Icons {
XXX("src/resoruces/icons/xyz.png");
private ImageIcon icon;
Icons(String path) {
try {
// will fail miserably in eclipse and after exporting to jar
URL imageURL = getClass().getClassLoader().getResource(path);
icon = new ImageIcon(imageURL);
} catch (Exception e) {
// works like a char in eclipse and after creating the jar file
// with the files in the same directory
System.out.println("getResoruce() did not work");
icon = new ImageIcon(path);
}
}
【问题讨论】: