1

I am working in Java Swing application. I am referring image in my program and it work fine when I run it in Eclipse but when I run it after exporting it doesnt show those files.

My directory hierarchy: enter image description here

Code 1: enter image description here

Code 2: enter image description here

While exporting the jar I have selected Library handling: Package required libraries into generated jar.

after converting jar to zip, the zip file contains all the resources folders in it. and also classpath file contains resources folder included.

I have referred many answers here but nothing helped me. Reffered Questions :

Exported JAR Won't Read Image

Picture inside .jar file wont work when I export it

Exporting Images with JAR in Eclipse (Java)

Eclipse exported Runnable JAR not showing images

Java images not appearing in JAR file

Eclipse exported Runnable JAR not showing images

Community
  • 1
  • 1
Suroor Ahmmad
  • 1,110
  • 4
  • 23
  • 33

1 Answers1

0

Try new ImageIcon("/res/images/icon.png") or new ImageIcon("/res/images/icon.png") depending on where you can find the image in the jar file. Because I think without the starting "/" it will try to find it outside the JAR file.

If this is not working then you can try loading the file with [yourclassname].class.getClass().getResourceAsStream(...)

gaRos
  • 2,463
  • 6
  • 22
  • 27
  • So are you sure that if you open the Zip file, that contains the path "/res/images/icon.png"? – gaRos Mar 31 '15 at 07:21