I created a small image loading application, it just loads a .png inside the res folder. In eclipse running it will just work fine. But when i export it to an jar the image isnt included in the jar, so it cant load it. I tried to add the res folder to the source path and it will include the image, but it includes it in the root off the folder (Wich isnt where the image is supposed to be in) Does anyone have an idea how i can add the res folder in the jar? It does load the image when i manually (With Lubuntus archivemanager) put the res folder in the jar.
Any ideas how i can add it in the jar with eclipse?Answer1:
You are on the right track when trying to make your "res" folder a java source folder. If you'd like to preserve "res" in the final path of the resources in the JAR, the res folder must sit inside a folder that's designated as the source folder.
You can either move res folder under your src folder or create a parent folder to hold res...
src (source folder) .. res .. .. image.png
src (source folder) resources (source folder) .. res .. .. image.pngAnswer2:
If you chose the "Export -> JAR File" option, you can select all folders and files you want to include. Those will be included properly, i.e. with their full name.
If you chose the "Export -> Runnable JAR file" option, this is not possible. In that case you can save the export script as an ANT build file. In the build file you can edit the export target to include the res folder and its contents.
That being said, in the long run, for making releases/JARs, Eclipses built-in functionality is pathetic. You really want to go the ant/maven way. It takes a bit of reading, but after that it's all automatic and far less hassle and far more flexible than anything Eclipse offers.