Video in progress
What is a "fat jar" in Spring Boot?
A fat jar is a single jar that holds your own classes plus all the dependency jars. Nothing else is needed for java -jar app.jar.
📖 Answer
After mvn package or gradle bootJar, the jar has a structure like this:
BOOT-INF/classes/ # your classes and resources
BOOT-INF/lib/ # all the libraries (spring, hibernate, jackson...)
org/springframework/boot/loader/ # special loader
META-INF/MANIFEST.MF
A regular Java jar can't read jars nested inside it. That's why Boot adds its own loader: MANIFEST.MF lists the Boot loader as Main-Class; it adds the jars in BOOT-INF/lib to the classpath and then calls your main class.
In practice, so you don't re-upload an 80 MB jar into the Docker image on every change, it gets split into layers (java -Djarmode=tools -jar app.jar extract --layers). Libraries change rarely and stay cached in their own layer; the only layer that gets updated is the one with your code.
Sign up to mark studied questions and save your progress.