[英]Where should my resource folder be with a runnable jar?
In eclipse, i have a project i am working on with resources that i call like this for example 在eclipse中,我有一个项目,我正在研究资源,我称之为例如
URL url = FighterComponent.class.getResource("/gfx/characters/");
File file = new File(url.getPath() + info.name + "/" + frame.path);
/gfx/ being a folder inside of res. / gfx /是res里面的一个文件夹。 res is my resource folder which i have linked by doing this:
res是我通过这样做链接的资源文件夹:
run > run configurations... > Classpath > Select user entries > Advanced > Add folder 运行>运行配置...>类路径>选择用户条目>高级>添加文件夹
My question now is that where should the res folder be after i exported my project into a runnable jar for my friends to be able to test it? 我现在的问题是,在我将项目导出到一个可运行的jar中之后,res文件夹应该放在哪里,以便我的朋友能够测试它? I tried putting it in the same folder as my jar and inside my jar and for both the URL was null.
我尝试将它放在与我的jar相同的文件夹中并放在我的jar中,因为这两个URL都是null。
Any idea ? 任何的想法 ?
If the name begins with a '/'
('\/')
, then the absolute name of the resource is the portion of the name following the '/'
. 如果名称以
'/'
('\/')
,则资源的绝对名称是'/'
后面的名称部分。
So, you should have a gfx/characters directory inside the jar file. 所以,你应该在jar文件中有一个gfx / characters目录。 Under this directory, if you have an image.jpg resource, you will have to retrieve it using:
在此目录下,如果您有image.jpg资源,则必须使用以下命令检索它:
URL url = TheClass.class.getResource("/gfx/characters/image.jpg");
You can also use the getResourceAsStream()
to get an InputStream
that you can read from. 您还可以使用
getResourceAsStream()
来获取可以读取的InputStream
。
You can put it at the root of your jar. 你可以把它放在罐子的根部。 Then people will be able to access the resources by
/res/gfx/..
然后人们将能够通过
/res/gfx/..
访问资源/res/gfx/..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.