【问题标题】:cannot read image in jar file: javafx无法读取 jar 文件中的图像:javafx
【发布时间】:2023-04-06 08:32:02
【问题描述】:

当我构建一个 jar 文件并运行它时,我看不到图像。 在 Eclipse 中一切正常。

图片应该是一个按钮

<effect>
    <ImageInput>
       <source>
          <Image url="file:./images/record_by_felickzs.PNG" />
       </source>
    </ImageInput>
</effect>

【问题讨论】:

    标签: java eclipse javafx jar


    【解决方案1】:

    那是因为在 Eclipse 上,图像没有被打包,所以它可以按照你的方式访问,但是当你导出一个 jar 文件时,图像被打包,你不能以这种方式访问​​ jar 内的文件,,,使用而是相对路径:

    <effect>
        <ImageInput>
           <source>
              <Image url="@../../images/record_by_felickzs.PNG" />
           </source>
        </ImageInput>
     </effect>
    

    编辑:用 png 替换 PNG

    【讨论】:

    • 感谢您的快速回答,但我仍然遇到同样的问题
    • 请尝试使用 .png 而不是 .PNG
    • 这没什么不同
    • 那么我们必须检查你的 jar 文件的内容
    猜你喜欢
    • 2012-10-26
    • 1970-01-01
    • 2011-08-28
    • 2017-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-30
    相关资源
    最近更新 更多