I am creating a program that uses gifs and jpgs as graphics. Those are stored in a folder called "Graphics". When I compile and run my program from the command line, everything is fine. But as soon as I put it in a JAR file and execute it, the graphics don't show. I tried putting the graphics folder into the jar file, but that didn't help.
When I just compile it and try it out I have the graphics folder in the same folder as the class files and it works. When I put it in a JAR I put the Graphics folder in the same folder as the JAR file and it did not work. Then I tried putting the Graphics folder in the JAR and that did not work, either
Regular file I/O does not work with resources in jar files. You need to use the resource/classloader approach, which will look something like this (assuming that 'Graphics' is a top-level directory in the jar file):