将java项目导出到带有图像的可运行jar文件

将java项目导出到带有图像的可运行jar文件,java,eclipse,export,Java,Eclipse,Export,我正在尝试导出一个包含som图像的java项目,但导出后图像不会显示。我读过这些类似的问题和答案: 我尝试了所有建议的不同选项,但导出项目后图像仍然没有显示 我尝试过这种文件结构: 使用此结构,我使用以下代码创建图像: Image picture = new Image("file:src/Pictures/download.png"); Image picture = new Image("file:Pictures/download.png"); 此文件结构: 使用此结构,我使用

我正在尝试导出一个包含som图像的java项目,但导出后图像不会显示。我读过这些类似的问题和答案:

我尝试了所有建议的不同选项,但导出项目后图像仍然没有显示

我尝试过这种文件结构:

使用此结构,我使用以下代码创建图像:

Image picture = new Image("file:src/Pictures/download.png");
Image picture = new Image("file:Pictures/download.png");
此文件结构:

使用此结构,我使用以下代码创建图像:

Image picture = new Image("file:src/Pictures/download.png");
Image picture = new Image("file:Pictures/download.png");
导出项目时,我选择了“将所需库打包到生成的JAR中”:

当我从Eclipse运行程序时,这些图像会显示出来,但一旦我导出它,它们就会消失。我做错了什么?我真的觉得我什么都试过了,但也许有一些简单的细节我错过了


谢谢

问题不在于创建jar文件,而在于您读取图像的方式,请务必在java代码中读取图像,如下所示

ImageIO.read( ClassLoader.getSystemResource( "image/button1.png" ) );

好的,你能再解释一下吗?我刚接触javafx,所以我不是专家;)该代码似乎返回一个缓冲图像。我想把我的图像放到图像视图中,以便在程序中显示它。但在创建图像视图时,似乎不能使用缓冲图像作为输入参数。如何使缓冲图像显示在程序中?我使用了这段代码,现在工作正常:ImageView imgViewPicture=new ImageView();尝试{BufferedImage buffered=ImageIO.read(ClassLoader.getSystemResource(“Pictures/download.png”);Image picture=SwingFXUtils.toFXImage(buffered,null);imgViewPicture=new ImageView(picture);imgViewPicture.setPreserveRatio(true);imgViewPicture.setFitHeight(250);}catch(IOE异常){//TODO自动生成的捕获块e.printStackTrace();}感谢您的帮助!:)
InputStream=getClass().getResourceAsStream(“/resources/icons/xyz.png”);ImageIcon=new ImageIcon(ImageIO.read(stream))
。您可以执行
icon.getImage()
来获取图像对象