Using Java to read a .jar manifest file

前端 未结 3 1720
渐次进展
渐次进展 2021-02-06 11:43

so I am trying to see if a .jar is valid or not, by checking some values in the mainfest file. What is the best way to read and parse the file using java? I thought of using thi

3条回答
  •  太阳男子
    2021-02-06 12:36

    The problem with using the jar tool is that it requires the full JDK to be installed. Many users of Java will only have the JRE installed, which does not include jar.

    Also, jar would have to be on the user's PATH.

    So instead I would recommend using the proper API, like this:

    Manifest m = new JarFile("anyjar.jar").getManifest();
    

    That should actually be easier!

提交回复
热议问题