我的第一个问题:
我一直试图解决这个问题几天,但我已经到了失去耐心的地步.以下是一些代码和我的项目结构.
问题:如何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);
}
}
Run Code Online (Sandbox Code Playgroud)
