Mittwoch, 11. Juni 2014

Extract the Class-Path from a JAR using SED

The Class-Path in a manifest file of a JAR exceeds in most cases the line width limit of manifest files. In this case the line is continued in the next line which starts with a space. In order to read the class path from a manifest file it is necessary to join the lines. The following sed command does it on Unix.

unzip -c example.jar META-INF/MANIFEST.MF |
sed -n '/^Class-Path: /,/^[^ ]/{s/^\(Class-Path:\)\? //;H};${g;s/\r\?\n//g;s/ /:/g;p}'

The command replaces the spaces in the class path of a manifest file with colons. The result can be used directly as an argument to a -classpath option.

Keine Kommentare: