1

I know how I can find and unzip the MANIFEST.MF from a jar:

https://stackoverflow.com/a/7066174/927493

But MANIFEST.MF has special formatting rules. Reading a "property" is harder than reading it from as "standard" property file because values may have line breaks.

What is a robust way to read a given property (like Implementation-URL) from a MANIFEST.MF using command line?

EDIT: I added an example. The broken lines seem to start with a space, but I haven't found a specification yet.

Build-Jdk: 1.8.0_161
Implementation-URL: http://ik-rep2.continentale.loc:8081/nexus/conten
 t/sites/site/de.something/release-plugin-ear/0.1.5-SN
 APSHOT/release-plugin-ear
J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Have you checked [What is the proper way to parse the entries of a manifest.mf file in jar?](https://stackoverflow.com/questions/18899123/what-is-the-proper-way-to-parse-the-entries-of-a-manifest-mf-file-in-jar)? – ernest_k Mar 27 '19 at 10:01
  • 1
    @ernest_k This is interesting, but it talks about reading it from _Java_, not from a command line. – J Fabian Meier Mar 27 '19 at 10:05
  • 1
    [this](https://stackoverflow.com/questions/14235872/unwrapping-a-java-manifest-file-fin-bash)? – Eugene Mar 27 '19 at 10:19
  • Could you give a sample input that includes an example of line breaking property ? Could you confirm that line breaking properties always begin their new lines with a space as shown in Eugene's link ? – Aserre Mar 27 '19 at 10:25
  • 2
    @JFMeier [Specification](https://docs.oracle.com/en/java/javase/12/docs/specs/jar/jar.html#manifest-specification) says: _No line may be longer than 72 bytes (not characters), in its UTF8-encoded form. If a value would make the initial line longer than this, it should be continued on extra lines (each starting with a single SPACE)._ – Würgspaß Mar 27 '19 at 11:23

1 Answers1

1

Using Eugene's link, you could start by properly formating your manifest.mf file, then pipe the formatted output to awk to extract the value of the property you need :

perl -0777 -wpe 's/\n //g' MANIFEST.MF | awk '/PROPERTY/{print $2}'  
Aserre
  • 4,916
  • 5
  • 33
  • 56