Eclipse exported Runnable JAR not showing images

后端 未结 8 1550
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 16:46

My images will not load when running a JAR file exported from Eclipse.

I have the images in a resources class package. I\'ve tried a images source folder as well wit

相关标签:
8条回答
  • 2020-11-22 17:21

    Unless you have to have you files in the jar, this is probably the simplest way of doing it:

    header = ImageIO.read(new File("./resources/header.jpeg"));

    header has to be an Image/BufferedImage. This goes to the folder that the runnable jar is within and looks for a folder called resources. http://i.stack.imgur.com/x8xtO.png

    0 讨论(0)
  • 2020-11-22 17:22

    Two Simple steps:

    1 - Add the folder to Build Path;

    2 - Use this:

        InputStream url = this.getClass().getResourceAsStream("/load04.gif");
        myImageView.setImage(new Image(url));
    
    0 讨论(0)
提交回复
热议问题