Issue
I have a problem to export my Jframe app with the background resource into jar file (without any external resource folder. I prefer to have everything into jar file for better portability). Here's the code. On Eclipse all work correctly, but when I export into jar file the app doesn't load because the resource "cccc.jpg" is not found. I have already tried the getResource() but it didn't work as well.
// Load Background image
BufferedImage img = null;
try {
img = ImageIO.read(new File("cccc.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
// Set Background image
Image dimg = img.getScaledInstance(640, 480, Image.SCALE_SMOOTH);
ImageIcon imageIcon = new ImageIcon(dimg);
setContentPane(new JLabel(imageIcon));
Solution
like
BufferedImage bufferedImage = ImageIO.read(MyClass.class.getResource("/images/cccc.jpg"));
see: Loading image from a resource Can't read input file
Answered By - guillaume girod-vitouchkina