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

前端 未结 9 1063
失恋的感觉
失恋的感觉 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:11

    I've found the comment by McDowell to be true - which MANIFEST.MF file gets picked up depends on the classpath and might not be the one wanted. I use this

    String cp = PCAS.class.getResource(PCAS.class.getSimpleName() + ".class").toString();
    cp = cp.substring(0, cp.indexOf(PCAS.class.getPackage().getName())) 
                  +  "META-INF/MANIFEST.MF";
    Manifest mf = new Manifest((new URL(cp)).openStream());
    

    which I adapted from link text

提交回复
热议问题