JAR 不显示图像?

发布于 2024-11-07 02:46:21 字数 188 浏览 5 评论 0原文

好吧,这是我的问题:

我创建了一个 jar (我之前已经做过很多次了),但它无法正常工作。我还有 3 个 java 文件;通常我有一个。我在主类中创建两个类的对象;创建对象时我需要做什么特别的事情吗?我使用的图像位于与 JAR 相同的文件夹中,因此这不是问题。

如果您想要/需要,我可以发布代码,尽管我不知道它会如何提供任何帮助。

Ok, here's my problem:

I created a jar (something I've done many times before), but it's not working correctly. I have 3 java files in yet; usually I have one. I create objects of two of the classes in the main class; is there anything special I have to do when creating the objects? The images that I use are in a folder that is in the same folder as the JAR, so that's not a problem.

I can post code if you want/need, though I don't see how it'll do any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热风软妹 2024-11-14 02:46:22

我使用的图像位于与 JAR 相同的文件夹中,因此这不是问题。

也许这一个问题。

我假设您正在尝试通过 Class.getResourceAsStream(...) 或类似的方式访问图像。如果是这样,类加载器将仅看到位于类路径上的目录树中的图像文件。按照您描述的方式,图像文件不在 JAR 文件中,因此您需要该目录的单独类路径条目。

(真正有帮助的是,如果您用更清晰的英语重写您的问题......并使用正确的术语。例如:“我在主类中创建两个类的对象”是无意义的)

The images that I use are in a folder that is in the same folder as the JAR, so that's not a problem.

Maybe it is a problem.

I presume that you are trying to access the images via the Class.getResourceAsStream(...) or something like that. If so, the classloader will only see the image files if they are in a directory tree that is on the classpath. The way that you described it, the image files are NOT in the JAR file, and therefore you need a separate classpath entry for the directory.

(What would really help would be if you rewrote your question in clearer English ... and using the correct terminology. For instance: "I create objects of two of the classes in the main class" is nonsensical. )

花开雨落又逢春i 2024-11-14 02:46:21

我还有 3 个 java 文件; ..

将类放入 Jar 文件中,而不是 .java 源文件中。

(令我惊讶的是,这就是答案!;)

I have 3 java files in yet; ..

Put classes in Jar files, not .java source files.

( It surprises me that was the answer! ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文