Accessing JAR resources

前端 未结 4 1519
太阳男子
太阳男子 2020-11-30 10:47

I have a jar file with resources (mainly configuration for caches, logging, etc) that I want to distribute.

I\'m having a problem with the relative path

4条回答
  •  离开以前
    2020-11-30 11:20

    Make sure that your resource folder is listed as a source folder in your project settings. Also, make sure that the resource folder is set to export when you build your jar.

    You can add a .zip extension to your jar file then open it up to ensure that your resources are included and at the expected location.

    I always use absolute paths like this:

    InputStream input = this.getClass().getResourceAsStream("/image.gif");
    

    When you use absolute paths, "/" is the root folder in the jar file, not the root folder of the host machine.

提交回复
热议问题