okio
okio copied to clipboard
Do something with nested .jar files on the classpath
As described here: https://github.com/square/wire/discussions/2209
Wire is crashing attempting to load a resource it shouldn't be loading.
java.io.FileNotFoundException: /app.jar!/BOOT-INF/lib/my-service-sdk-1.2.0.jar (No such file or directory)
at java.base/java.io.RandomAccessFile.open0(Native Method) ~[na:na]
at java.base/java.io.RandomAccessFile.open(RandomAccessFile.java:344) ~[na:na]
at java.base/java.io.RandomAccessFile.<init>(RandomAccessFile.java:259) ~[na:na]
at java.base/java.io.RandomAccessFile.<init>(RandomAccessFile.java:213) ~[na:na]
at okio.JvmSystemFileSystem.openReadOnly(JvmSystemFileSystem.kt:82) ~[okio-jvm-3.0.0.jar!/:na]
at okio.internal.ZipKt.openZip(zip.kt:67) ~[okio-jvm-3.0.0.jar!/:na]
at okio.internal.ResourceFileSystem$Companion.toJarRoot(ResourceFileSystem.kt:201) ~[okio-jvm-3.0.0.jar!/:na]
at okio.internal.ResourceFileSystem$Companion.toClasspathRoots(ResourceFileSystem.kt:184) ~[okio-jvm-3.0.0.jar!/:na]
at okio.internal.ResourceFileSystem$roots$2.invoke(ResourceFileSystem.kt:47) ~[okio-jvm-3.0.0.jar!/:na]
at okio.internal.ResourceFileSystem$roots$2.invoke(ResourceFileSystem.kt:47) ~[okio-jvm-3.0.0.jar!/:na]
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) ~[kotlin-stdlib-1.6.10.jar!/:1.6.10-release-923(1.6.10)]
at okio.internal.ResourceFileSystem.getRoots(ResourceFileSystem.kt:47) ~[okio-jvm-3.0.0.jar!/:na]
at okio.internal.ResourceFileSystem.<init>(ResourceFileSystem.kt:51) ~[okio-jvm-3.0.0.jar!/:na]
at okio.Okio__JvmOkioKt.asResourceFileSystem(JvmOkio.kt:233) ~[okio-jvm-3.0.0.jar!/:na]
at okio.Okio.asResourceFileSystem(Unknown Source) ~[okio-jvm-3.0.0.jar!/:na]
at com.squareup.wire.schema.CoreLoader$resourceFileSystem$2.invoke(CoreLoader.kt:46) ~[wire-schema-jvm-4.3.0.jar!/:na]
at com.squareup.wire.schema.CoreLoader$resourceFileSystem$2.invoke(CoreLoader.kt:45) ~[wire-schema-jvm-4.3.0.jar!/:na]
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) ~[kotlin-stdlib-1.6.10.jar!/:1.6.10-release-923(1.6.10)]
at com.squareup.wire.schema.CoreLoader.getResourceFileSystem(CoreLoader.kt:45) ~[wire-schema-jvm-4.3.0.jar!/:na]
at com.squareup.wire.schema.CoreLoader.load(CoreLoader.kt:51) ~[wire-schema-jvm-4.3.0.jar!/:na]
Just for the information whoever will find this ticket trying to figure out what to do please find the workaround we found. We ended up updating the dockerfile to unpack the spring boot fat jar like below:
ARG JAR_FILE=build/libs/worker.jar
COPY ${JAR_FILE} worker.jar
# Extract the layers
RUN java -Djarmode=layertools -jar worker.jar extract
# Add layers to the image
WORKDIR /app
COPY dependencies/ ./
COPY spring-boot-loader/ ./
COPY snapshot-dependencies/ ./
COPY application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
Spring Boot is smart to detect this setup and load the modules appropriate and okio is also happy being placed as a regular file.