what is the difference between `bootJar` and `shad...
# spring
s
what is the difference between
bootJar
and
shadowJar
. Can I use
shadowJar
for Spring boot applications?
ok so, bootJar will bundle a tomcat server inside the jar, which shadowJar wont. Is that correct?
d
By
shadowJar
I assume you refer to this plugin: https://github.com/johnrengelman/shadow? That plugin copies all the dependencies and your code into one fat jar file (with only classes inside). It can rewrite package names as well while it does so. Spring boot on the other hand generates a jar file with all your classes inside
BOOT-INF/classes
and all your dependencies as jar files (jar file inside jar file) in
BOOT-INF/lib
. It then has a main class, which sets up a class loader to load these contained files and dependencies and then invokes your actual main class. You can't simply use a boot-jar file as a dependency for another project, which you could do with a shadow jar. The boot jar is only meant to create a single runnable jar file. Shadow also achieves that, but boot does it in a more compatible way (dependency jar files are kept as-is)
s
thanks a lot!!!
So when would you use a jar build using shadow instead of boot jar?
d
The only scenario is if you have a library that for some reason must not have any transitive dependencies and thus must ship all its dependencies shaded into one jar. For executable jars I'd always prefer the boot-jar approach
s
I see. I get your point now. Thanks for explaining!!
m
It it's not Spring Boot, but you want an executable, Gradle also has the https://docs.gradle.org/current/userguide/application_plugin.html. This also builds scripts for running the jar file. So depending on your use case, you have a few options.
1902 Views