Search code examples
javaimagejariconsembedded-resource

image icon not appearing outside eclipse


I made a chess game with a gui, using images for the pieces. It works perfectly when run in eclipse. However, I tried exporting the jar (from eclipse) and running it in cmd but none of the images appear (the game itself however works perfectly, i just have to guess where the pieces are). I'm going to assume that there is an issue with the addresses of the images... The problem is, I can't even seem to be able to open any of the files within the jar file to see what, if anything is going on.

In eclipse, all the images were in a package within the scr folder, and they are definitely within the jar.

Any advice?


Solution

  • If you want to load images within your jar file you will need to use the Class.getResource(String) method.

    For detailed instructions see the How to Use Icons section in the Java Tutorial.