I am writing a simple game in Eclipse (Java), it requires some images. It works fine in Eclicpse, but when I export it (as a runnable jar) there are no images (just empty places instead of them). I have a source folder called "images" in the project, and I adress the images this way: "images/name.png". THe images are exported right into the jar. I have tried placing images folder in an resource folder, still didn't work. I've also placed the images in different places in the jar, didn't work. How do I make Eclipse export the project correctly? (I'm just a begginer, so I don't know which information should I post)
Asked
Active
Viewed 542 times
0
-
Check this question: http://stackoverflow.com/questions/25635636/eclipse-exported-runnable-jar-not-showing-images – Leandro Carracedo Mar 08 '15 at 21:07
-
Have you clicked the "Package required libraries into generated JAR" option when exporting it? – Brunaldo Mar 08 '15 at 21:08
-
@Brunaldo Yes, I have – Jakub Kamiński Mar 08 '15 at 21:15
-
@PatrickLC for some reason, when I use the code from the best anwser, it just doesn't run – Jakub Kamiński Mar 08 '15 at 21:26
1 Answers
1
If you want to include and access resources as images or configuration files from a runnable jar, you have to place them in your source folder to include it. Alternatively you could provide the full path to the resources, which of course makes it difficult to port to other systems...
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("file/test.xml").getFile());
http://www.mkyong.com/java/java-read-a-file-from-resources-folder/

Marvin Emil Brach
- 3,984
- 1
- 32
- 62