How to includes all images in jar file using eclipse

后端 未结 4 1615
生来不讨喜
生来不讨喜 2020-11-29 10:38

I made a java application and bundled all classes in a jar file. When I run the project from eclipse, my application is running successfully. But when I try to run my

4条回答
  •  天涯浪人
    2020-11-29 11:16

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

    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"));
    

提交回复
热议问题