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

标签 java eclipse resources

您好,我在 .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/

相关文章:

java - org.openqa.selenium.WebDriverException : chrome not reachable using Selenium and ChromeDriver

python - 隐藏 Unresolved 导入错误

java - Eclipse 插件代码找不到 "javax.inject.Inject"类,插件 jar 现在不在插件目录中

java - Eclipse E4 中的 FilteredItemsSelectionDialog

eclipse - 如何用Java创建Eclipse文件夹资源过滤器

html - Css 外部资源停止工作

java - Java中这两个字符串有什么区别

java - 使用 robotium 检查对话框提示 - 如果没有则需要 if 语句

eclipse - 尝试通过ResourcesPlugin获取工作区时出现"Workspace is closed"异常

java - 更改 jPanel 中矩形的边框