Java JAR Export Images Folder Is Wrong

雨燕双飞 提交于 2020-01-16 03:52:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!