在 Eclipse (Java) 中使用 JAR 导出图像 [英] Exporting Images with JAR in Eclipse (Java)

查看:31
本文介绍了在 Eclipse (Java) 中使用 JAR 导出图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做一个需要外部图像来显示的小项目.我不太熟悉如何使用 Eclipse,这是我第一次尝试导出已完成的项目,以便与他人共享.现在,似乎我可以让我的图像显示的唯一方法是在我的硬盘驱动器上分配一个特定的文件夹并让代码中的图像路径转到那个文件夹.我正在寻找一种方法将图像作为 JAR 的一部分或作为同一包的一部分导出,因此当我将此程序发送给其他人时,我不必向他们发送单独的图像存档文件夹.我也有兴趣了解我需要做什么才能让我的代码引用该包中的图像,这样它们就可以在没有外部文件夹的情况下工作.我已经阅读了 Eclipse 中的某种包系统,但到目前为止还没有弄清楚如何使用它.可以用一些解释!

I've been working on a little project that requires external images for display. I'm not all that familiar with how to use Eclipse and this is my first time attempting to export a completed project so I can share it with others. Right now, it seems the only way I can get my images to show up is if I assign a specific folder on my hard drive and have the image paths in the code go to that. I'm looking for a way to export the images as part of my JAR or as part of the same package so when I go to send this program to other people, I don't have to send them a separate archived folder of images. I'd also be interested in learning what I need to do to have my code reference the images within that package so they'll work without an external folder. I have read about some kind of package system within Eclipse, but have thus far had no luck in figuring out how to use it. Could use some explicating!

提前感谢任何愿意给我两美分的人.

Thanks in advance to anyone willing to give me their two cents.

推荐答案

如果它们在 jar 中,您可能需要将它们作为类路径资源加载.参见:getClass().getClassLoader().getResourceAsStream(...)

you might need to load them as class path resources if they are within a jar. see: getClass().getClassLoader().getResourceAsStream(...)

这篇关于在 Eclipse (Java) 中使用 JAR 导出图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆