I have create swing application which is bundled in jar file. (execuable jar file). ( jar file contains class file , images and manifest file ) For ex. :
My class name ShowImg which display images . (images from images folder) Toolkit kit = comp.getToolkit(); Image img = kit.createImage("./images/nature.jpg"); using following command i have created jar file. jar -cvfm test.jar man.mf ShowImg.class images\nature.jpg
When i run jar file in same directory where images folder exists it works fine. But when i copy test.jar file some where else it doesn't work. It displays only frame not image.
HI , I have used following code for display imageIcon on Jbutton. It throws NullPointerException when i try to run application through jar file. JButton butt = new JButton( ); URL url = getClass().getClassLoader().getResource("images/ash.jpg");
ImageIcon imgSearch = new ImageIcon(url); butt.setIcon(imgSearch); Excetion :
I believe you need to make the path to the file an absolute path, since the class is in the default package. I'm not 100% sure about this but it's worth a try. Add a "/" to the beginning of the image file path.