Java JAR导出映像文件夹是错误的 [英] Java JAR Export Images Folder Is Wrong
问题描述
问题是...我有一个文件夹在Eclipse中列为我的构建路径中的一个类文件夹,我命名为res。 res文件夹中的另一个名为Images。当我导出我的.JAR,并查看其中的文件时,我看到的只有图像文件夹,而不是res,这会混淆我在项目中的图像加载方法。
有没有任何想法,如何使res文件夹被导出不同,或者我如何使我的图像方法在Eclipse中的测试模式以及.jar中正常工作?
您的图片应该在源文件夹中(我们称之为资源),并遵守与Java源文件相同的包层次结构规则。 >
如果您使用 SomeClass.class.getResourceAsStream(/ res / images / foo.png)
加载图像,则资源源文件夹中必须有一个名为res的包,其中包含一个名为images的包,其中包含 foo.png
:
$
Application.java
SomeClass.java
资源< - 源折叠呃
res
图像
foo.png
生成的jar文件将如下所示:
theJar.jar
com
foo
bar
Application.class
SomeClass.class
res
图片
foo.png
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?
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
这篇关于Java JAR导出映像文件夹是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!