Reputation: 487
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 isn't included in the jar, so it can't 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 (Which isn't 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?
Upvotes: 0
Views: 485
Reputation: 2295
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.
Upvotes: 0
Reputation: 29139
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...
Option 1:
src (source folder)
.. res
.. .. image.png
Option 2:
src (source folder)
resources (source folder)
.. res
.. .. image.png
Upvotes: 1