java: [BUG] ModelMapper cannot register any resource classes if packaged in executable fat jar
Describe the bug
if the project is packaged in a whole executable fat jar, e.g:
$ jar -tf my-project-executable.jar
META-INF/
META-INF/MANIFEST.MF
org/
org/springframework/
org/springframework/boot/
...
BOOT-INF/lib/gson-fire-1.8.5.jar
BOOT-INF/lib/joda-time-2.10.5.jar
BOOT-INF/lib/joda-convert-2.2.1.jar
BOOT-INF/lib/client-java-proto-11.0.1.jar
BOOT-INF/lib/client-java-11.0.1.jar # NESTED JAR FILE
...
the classes under io.kubernetes.client.openapi.model will be packaged as a nested jar file inside the fat jar file. when we’re trying scanning the classes via the class-loader. the URL for the pre-built resource classes will be e.g.:
file:/home/admin/release/run/target/boot/agent-installer-bootstrap-0.0.1-SNAPSHOT-executable.jar!/BOOT-INF/lib/client-java-api-11.0.1.jar!/io/kubernetes/client/openapi/models
then we will get a wrong URL to the jar file when we’re extracting file path from the resource path above:
/home/admin/release/run/target/boot/agent-installer-bootstrap-0.0.1-SNAPSHOT-executable.jar!/BOOT-INF/lib/client-java-api-11.0.1.jar
b/c we cant correctly open the actual jar file using the file path above, no classes will be found in the end… one feasible solution i can think of is to visit the nested jar file recursively if multiple ! is found in the URL.
** Client Version ** e.g. `11.0.1
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 28 (13 by maintainers)
Commits related to this issue
- fix(k8s-client-library): manually register Job class in ModelMapper (related to https://github.com/kubernetes-client/java/issues/1659) — committed to kamieniarzk/kube-config-scanner by kamieniarzk 9 months ago
key point and solution is found.
the problem codes here:
Yaml.class.getClassLoader() can not read any class in “io.kubernetes.client.openapi.models” cause of bad jar url.
if (entryName.startsWith(packageName) && entryName.length() > packageName.length() + 5)never hit.unzip my jar like
soulution
dont use fat, make lib and app jar split
use to start app
I’ve submitted a PR addressing the bug and improving the code as per the issue description… see https://github.com/kubernetes-client/java/pull/2620
I suggest tag this “bug” into “known issues”, because Springboot project default package type is fat jar and this known issue may be hit easily