问题
and thank you for reading this and any help you give me. Well...I'm using Eclipse, and I'm trying to export my project as a .jar.
The problem is...I have a folder that is listed in Eclipse as a class folder in my build path that I named "res." Inside the res folder is another named "Images." When I export my .JAR, and look at the files in it, all I see is the Images folder, not the res, which messes up my image loading methods in the project.
Are there any ideas on either how to get the res folder to be exported differently or how I could make my image methods to work properly both in test mode in Eclipse, and as a .jar?
回答1:
Your images should be in a source folder (let's call it "resources"), and respect the same package hierarchy rules as Java source files.
If you load your images with SomeClass.class.getResourceAsStream("/res/images/foo.png"), then there must be a package named "res" in the resources source folder, containing a package named "images", containing foo.png:
src <- source folder
com
foo
bar
Application.java
SomeClass.java
resources <- source folder
res
images
foo.png
The generated jar file will look like this:
theJar.jar
com
foo
bar
Application.class
SomeClass.class
res
images
foo.png
来源:https://stackoverflow.com/questions/11209621/java-jar-export-images-folder-is-wrong