且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用eclipse在jar文件中包含所有图像

更新时间:2023-09-30 13:08:10

您需要从类路径而不是从本地磁盘文件系统获取它.

You need to get it from the classpath instead of from the local disk file system.

假设 images 实际上是一个包,并且这个包与当前类在同一个 JAR 中,那么这样做:

Assuming that images is actually a package and that this package is inside the same JAR as the current class, then do so:

final public ImageIcon iReport = 
    new ImageIcon(getClass().getResource("/images/Report.png"));