One liner for listing contents of file within war

2020-04-30 18:41发布

问题:

I need to be able to read the contents of a file (say MANIFEST) within a jar file. Currently I do this by extracting the contents of the file and then listing it

${JAVA_HOME}/bin/jar xvf SOME_WAR_FILE.war META-INF/MANIFEST.MF
cat META-INF/MANIFEST.MF

Is it possible to do this using a one liner, without extracting the contents ?

回答1:

Is this what you are looking for?

unzip -qc SOME_WAR_FILE.war META-INF/MANIFEST.MF

See the previous answer here.



回答2:

What about this?

unzip -p your.jar META-INF/MANIFEST.MF | cat

the -p option says:

extract files to pipe, no messages

That | cat isn't really necessary. It'll print to standard out without it.



回答3:

A jar or war file is just a standard zip compressed archive, so you can use standard unzip with the -c option to direct it to stdout

$ file your.jar
your.jar: Zip archive data, at least v1.0 to extract
$ unzip -c your.jar META-INF/MANIFEST.MF
file contents
file contents


标签: java jar