jar文件中的图像 [英] Images in jar file
问题描述
我制作了一个Java应用程序,并将所有类捆绑在jar文件中.当我从eclipse运行项目时,我的应用程序已成功运行,但未从所需目录中获取图像.请让我知道如何显示这些图像图像文件提供给最终用户(例如我们提供的.jar文件)
I made a java application and bundled all classes in jar file.When I run the project from eclipse my app is running successfully,but it is not fetching the images from the desired directory.Please let me know how can we present these image files to the end user (like we present .jar file)
推荐答案
尝试分别使用 getResourceAsStream()
.代码中的 getResource()
.这样,无论您决定将图像放在jar还是目录中,都将能够使用相同的代码.在此处可以找到很好的解释.关于在Eclipse开发过程中将映像放置到正确的路径,请遵循
Try using getResourceAsStream()
resp. getResource()
in your code. That way you will be able to use the same code whether you decide to put your images in a jar or in a directory. A good explanation can be found here.
Concerning the right path where to put your images during Eclipse development, follow this recommendation.
这篇关于jar文件中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!