Including a launch script in a Spring Boot far jar using the Maven and Gradle build plugins results in a jar file that is not well formed and is not compatible with some tools (as noted in the Maven plugin documentation).

Apache Commons Compress library utilities like ZipFile.getEntries() fail to find the central directory in such a jar file and return an empty set, which causes issues with other Boot tooling.

Other tools will not recognize the file as a valid jar or zip (notably Go-based programs like pack):

$ pack build docker.io/library/demo --path build/libs/demo-0.0.1-SNAPSHOT.jar
ERROR: invalid app path 'build/libs/demo-0.0.1-SNAPSHOT.jar': app path must be a directory or zip

The Linux zip utility has an option that can be used to fix up the zip directory data to account for the extra launch script data at the beginning of the file:

  -A
  --adjust-sfx
         Adjust  self-extracting  executable archive.  A self-extracting executable archive is
         created by prepending the SFX stub to an existing archive. The -A option tells zip to
         adjust  the  entry offsets stored in the archive to take into account this "preamble"
         data.
$ zipinfo demo-0.0.1-SNAPSHOT.jar
Archive:  demo-0.0.1-SNAPSHOT.jar
Zip file size: 18436305 bytes, number of entries: 129
warning [demo-0.0.1-SNAPSHOT.jar]:  9123 extra bytes at beginning or within zipfile
  (attempting to process anyway)
drwxr-xr-x  2.0 unx        0 bX defN 20-Jul-09 17:24 META-INF/
-rw-r--r--  2.0 unx      485 bl defN 20-Jul-09 17:24 META-INF/MANIFEST.MF
drwxr-xr-x  2.0 unx        0 bl defN 80-Feb-01 00:00 org/
drwxr-xr-x  2.0 unx        0 bl defN 80-Feb-01 00:00 org/springframework/
drwxr-xr-x  2.0 unx        0 bl defN 80-Feb-01 00:00 org/springframework/boot/
...

$ zip --adjust-sfx demo-0.0.1-SNAPSHOT.jar
Zip entry offsets appear off by 9123 bytes - correcting...

$ zipinfo demo-0.0.1-SNAPSHOT.jar
Archive:  demo-0.0.1-SNAPSHOT.jar
Zip file size: 18434961 bytes, number of entries: 129
drwxr-xr-x  2.0 unx        0 bx defN 20-Jul-09 17:24 META-INF/
-rw-r--r--  2.0 unx      485 b- defN 20-Jul-09 17:24 META-INF/MANIFEST.MF
drwxr-xr-x  2.0 unx        0 b- defN 80-Feb-01 00:00 org/
drwxr-xr-x  2.0 unx        0 b- defN 80-Feb-01 00:00 org/springframework/
drwxr-xr-x  2.0 unx        0 b- defN 80-Feb-01 00:00 org/springframework/boot/
...

It would be nice if the build plugins could fix up the jar file in a similar way.

Comment From: scottfrederick

An issue has been created in the Apache Commons Compress project to add a feature that would make the fix in Spring Boot very simple. Blocking this issue for now, until we get a response on the Commons Compress issue.

Comment From: scottfrederick

A pull request has been created to implement the requested feature in Apache Commons Compress.

Comment From: wilkinsona

The changes have been merged and are available in snapshots. We're now waiting for the release of 1.21.