How do you create a MANIFEST.MF that's available when you're testing and running from a jar in production?

前端 未结 9 1036
失恋的感觉
失恋的感觉 2020-12-28 16:28

I\'ve spent far too much time trying to figure this out. This should be the simplest thing and everyone who distributes Java applications in jars must have to deal with it.

9条回答
  •  [愿得一人]
    2020-12-28 17:22

    You can access the manifest (or any other) file within a jar if you use the same class loader to as was used to load the classes.

    this.getClass().getClassLoader().getResourceAsStream( ... ) ;
    

    If you are multi-threaded use the following:

    Thread.currentThread().getContextClassLoader().getResourceAsStream( ... ) ;
    

    This is also a realy useful technique for including a default configuration file within the jar.

提交回复
热议问题