【问题标题】:Images and text file doesnt show in the exported runnable jar file导出可运行 jar 文件中不显示图像和文本文件
【发布时间】:2015-03-25 18:49:43
【问题描述】:

我正在使用 Java Swing 应用程序。我在我的程序中引用图像,当我在 Eclipse 中运行它时它工作正常,但是当我在导出后运行它时它不显示这些文件。

我的目录层次结构:

代码 1:

代码 2:

在导出我选择的 jar 时 库处理:将所需库打包到生成的 jar 中。

将 jar 转换为 zip 后,zip 文件包含其中的所有资源文件夹。 并且类路径文件也包含资源文件夹。

我在这里提到了很多答案,但没有任何帮助。 参考问题:

Exported JAR Won't Read Image

Picture inside .jar file wont work when I export it

Exporting Images with JAR in Eclipse (Java)

Eclipse exported Runnable JAR not showing images

Java images not appearing in JAR file

Eclipse exported Runnable JAR not showing images

【问题讨论】:

    标签: java jar export runnable


    【解决方案1】:

    尝试new ImageIcon("/res/images/icon.png")new ImageIcon("/res/images/icon.png"),具体取决于您可以在 jar 文件中找到图像的位置。因为我认为没有开始的“/”它会尝试在 JAR 文件之外找到它。

    如果这不起作用,那么您可以尝试使用 [yourclassname].class.getClass().getResourceAsStream(...) 加载文件

    【讨论】:

    • 那么你确定如果你打开包含路径“/res/images/icon.png”的Zip文件吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    • 2014-05-06
    • 2014-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-16
    相关资源
    最近更新 更多