Skip to content

Support prefix bytes with fat jars #1073

@aantono

Description

@aantono

When trying to create a self-starting bash script with embedded jar (https://coderwall.com/p/ssuaxa) the startup throws an exception.

Exception in thread "main" java.lang.IllegalStateException: java.io.IOException: Unable to read bytes
    at org.springframework.boot.loader.ExecutableArchiveLauncher.<init>(ExecutableArchiveLauncher.java:52)
    at org.springframework.boot.loader.ExecutableArchiveLauncher.<init>(ExecutableArchiveLauncher.java:44)
    at org.springframework.boot.loader.JarLauncher.<init>(JarLauncher.java:30)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:45)
Caused by: java.io.IOException: Unable to read bytes
    at org.springframework.boot.loader.jar.Bytes.get(Bytes.java:50)
    at org.springframework.boot.loader.jar.JarEntryData.<init>(JarEntryData.java:66)
    at org.springframework.boot.loader.jar.JarEntryData.fromInputStream(JarEntryData.java:170)
    at org.springframework.boot.loader.jar.JarFile.loadJarEntries(JarFile.java:136)
    at org.springframework.boot.loader.jar.JarFile.<init>(JarFile.java:126)
    at org.springframework.boot.loader.jar.JarFile.<init>(JarFile.java:107)
    at org.springframework.boot.loader.jar.JarFile.<init>(JarFile.java:97)
    at org.springframework.boot.loader.archive.JarFileArchive.<init>(JarFileArchive.java:47)
    at org.springframework.boot.loader.Launcher.createArchive(Launcher.java:154)
    at org.springframework.boot.loader.ExecutableArchiveLauncher.<init>(ExecutableArchiveLauncher.java:49)
    ... 3 more

When testing the file with jar tvf run.sh the content of the file gets printed just fine.

After reading http://mesosphere.io/2013/12/07/executable-jars/ it appears that the Zip/Jar format supports prepended arbitrary, non-Zip data and yet remain interpretable to the Zip decompressor, which is what is being used to create self-executing applications.

For some reason the Bytes parsing errors when trying to read that kind of jar. :(

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions