Loading ImageIcon from JAR or file system

后端 未结 1 636
野的像风
野的像风 2020-12-03 18:15

I have a simple program that needs to display images. I know how to do this running the code from Eclipse and I know how to do it running from a JAR file, but I\'d like a so

相关标签:
1条回答
  • 2020-12-03 18:44

    Put the images folder inside the src folder, and Eclipse will copy the images into the target folder (bin or classes, generally), which will make them available from the classpath, just as if they were in your jar in the released version of your app.

    getResource() doesn't look in a jar. It looks in the classpath of the classloader. Whether the image is in a jar or not is thus not important. It must be in the classpath. And obviously the target folder of eclipse (bin or classes, generally) is in the runtime classpath of the app when you launch it from Eclipse.

    0 讨论(0)
提交回复
热议问题