I'm making a game and I need to show images for the game to be playable. To make these images show up, I use ImageIO.read
and all the images are showing up fine when I run the code in Eclipse. The images that I use are in a separate folder as my main class but I set up this folder as a source folder in the build path.
I've tried to use getClass().getClassLoader().getResource("image.jpg")
as well as main.class.getResource("image.jpg")
, I've tried to write a /image.jpg
instead and for the Runnable Jar file, I've tried to extract the libraries and package the libraries and all these things worked fine in Eclipse but not in the JAR file...
My current code is like this:
File prisonCellFile = new File(main.class.getResource("cellule.jpg").getURI());
prisonCell = ImageIO.read(prisonCellFile);
Except for the images, everything else works fine in the jar file, and I saw that the images were exported into the jar file, but they are just not showing up... do you know what I did wrong?