My images will not load when running a JAR file exported from Eclipse.
I have the images in a resources class package. I've tried a images source folder as well with no luck.
Works perfectly when loaded from Eclipse. The images are in the exported JAR file, so they're exporting fine.
I've tried:
label.setIcon(new ImageIcon(MainFrame.class.getResource("/resources/header.jpg")));
I've also tried:
URL url = getClass().getResource("/resources/header.jpg");
Image image = Toolkit.getDefaultToolkit().getImage(url);
label.setIcon(new ImageIcon(image));
And:
try
{
label.setIcon(new ImageIcon(ImageIO.read(getClass().getResource("/resources/header.jpg"))));
}
catch (IOException e1)
{
e1.printStackTrace();
}
Any suggestions?
/resources
fromgetClass().getResource("/resources/header.jpg");
because whe you build application's JAR there ll be no/resources
directory. – Acnoderesources
included in the build path? – Sasha