gpt4 book ai didi

java - 找不到资源...可以在 eclipse 中运行,但不能从 jar 中运行

转载 作者:行者123 更新时间:2023-12-01 13:54:00 26 4
gpt4 key购买 nike

您好,我在 .jar 中加载资源时遇到了一些问题。在 Eclipse 中,我使用路径“data//guis//play.png”创建图像文件,但是当我尝试运行 jar 时,我得到一个异常,即无法找到资源,即使打包在与以下结构相同的结构中也是如此我在 eclipse 中有它。我该如何补救?

最佳答案

您声明:

Hello I'm having a bit of trouble with resource loading in .jar. In eclipse, I create image files with the path "data//guis//play.png" but when I try to run the jar, i get the exception that the resource could not be found, even when packaged in the same structure as I have it within eclipse. How do I rememdy this?

但这正是您的问题可能的原因 - 您正在尝试创建文件,但 Jars 内部不存在文件(正如 Java 所见)。相反,将图像作为资源而不是文件加载。

要获得更详细的帮助,您将需要显示更多相关代码以及 jar 文件的结构。

请从命令行运行此命令并在此处显示结果:

jar tf MyJarFile.jar  

当然,当您运行此行时,您将使用您的 jar 文件名。

关于java - 找不到资源...可以在 eclipse 中运行,但不能从 jar 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19738796/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com