JAR 不显示图像?
好吧,这是我的问题:
我创建了一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许这是一个问题。
我假设您正在尝试通过 Class.getResourceAsStream(...) 或类似的方式访问图像。如果是这样,类加载器将仅看到位于类路径上的目录树中的图像文件。按照您描述的方式,图像文件不在 JAR 文件中,因此您需要该目录的单独类路径条目。
(真正有帮助的是,如果您用更清晰的英语重写您的问题......并使用正确的术语。例如:“我在主类中创建两个类的对象”是无意义的)
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. )
将类放入 Jar 文件中,而不是 .java 源文件中。
(令我惊讶的是,这就是答案!;)
Put classes in Jar files, not .java source files.
( It surprises me that was the answer! ;)