How to read MANIFEST.MF file from JAR using Bash

后端 未结 6 1828
[愿得一人]
[愿得一人] 2020-12-07 11:00

I need to read MANIFEST.MF maven manifest file from \"some.jar\" using bash

6条回答
  •  暖寄归人
    2020-12-07 11:13

    use unzip:

    $ unzip -q -c $JARFILE_PATH META-INF/MANIFEST.MF
    

    that will quietly (-q) read the path META-INF/MANIFEST.MF from the jarfile (which is compressed using the zip format) to stdout (-c). You can then pipe the output to other command to answer questions like 'what is the main class for this jar:

    $ unzip -q -c $JARFILE_PATH META-INF/MANIFEST.MF | grep 'Main-Class' | cut -d ':' -f 2
    

    (this removes all lines which don't contain the string Main-Class, then splits the line at :, keeping only the second field, the class name). Of course, either define $JARFILE_PATH appropriately or replace $JARFILE_PATH with the path to a jarfile you're interested in.

提交回复
热议问题