Search code examples
bashshellmanifest.mf

How to read an entry from Java's MANIFEST.MF file where values are multiline in shell?


I have a MANIFEST.MF which looks like below

Manifest-Version: 1.0
Created-By: Maven JAR Plugin 3.3.0
Build-Jdk-Spec: 17
Implementation-Title: cengine
Implementation-Version: 0.0.1-SNAPSHOT
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.spotnana.obt.commissionengine.CommissionEngineApplicati
 on
Spring-Boot-Version: 3.0.13
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx
Spring-Boot-Layers-Index: BOOT-INF/layers.idx

I want to read Start-Class from the above MANIFEST.MF file. I tried the solution as mentioned here.

Manifest Specification says like below

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).

On trying

perl -0777 -wpe 's/\n //g' MANIFEST.MF | awk '/Start-Class/{print $2}' 

It is showing up like

onm.spotnana.obt.commissionengine.CommissionEngineApplicati

Solution

  • It seems to be a Windows line ending (\r\n) messing up the pattern matching.

    perl -0777 -wpe 's/\r?\n //g' MANIFEST.MF | awk '/Start-Class/{print $2}' 
    

    Added \r? to cater for both cases, Linux and Windows.