Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust fat jar central directory to account for launch script #22336

Closed
scottfrederick opened this issue Jul 14, 2020 · 3 comments
Closed

Adjust fat jar central directory to account for launch script #22336

scottfrederick opened this issue Jul 14, 2020 · 3 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@scottfrederick
Copy link
Contributor

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.

@scottfrederick scottfrederick added type: enhancement A general enhancement for: team-attention An issue we'd like other members of the team to review labels Jul 14, 2020
@philwebb philwebb added this to the 2.4.x milestone Jul 15, 2020
@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Jul 15, 2020
@wilkinsona wilkinsona changed the title Adjust far jar directory to account for launch script Adjust far jar central directory to account for launch script Jul 27, 2020
@scottfrederick scottfrederick self-assigned this Jul 30, 2020
@scottfrederick scottfrederick changed the title Adjust far jar central directory to account for launch script Adjust fat jar central directory to account for launch script Jul 30, 2020
@scottfrederick
Copy link
Contributor Author

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.

@scottfrederick
Copy link
Contributor Author

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

@philwebb philwebb modified the milestones: 2.4.x, 2.5.x Oct 19, 2020
@wilkinsona
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants