FAT Jar [#-#]น้องจาร์อ้วน

Nami Oyamada
Nov 4 · 2 min read

Getting a little knowledge about the Fat jar.

What is a FAT JAR ? !!!!! => It’s a single JAR file that contains compiled classes files, resources and packed it together (included all dependencies files and all dependencies libraries).

Advantage : All resource files are in a packed and its also avoids dependency version issues.
Disadvantage: Use “Bootstrap” classloader to enable Java to load classes from the wrapped JAR files. For the development, debugging class loader is more complex. For loading resouces, its used “getResource()” command to
get the resouces when loading a lot of jars can be issues , due to locking inside URLClassPath.

How to build a FAT JAR ? => It has many build systems to buuild a fat jar such as Gradle , Apache Maven, Apache Ant and etc.

The example to create a Fat jar

(Note: spring-boot application)

The structure of project is diplayed below :

  1. ${Project}/src/main/java/
  2. ${Project}/src/main/resources/
  3. ${Project}/src/test/java/
1. We added "Spring-boot-maven-plugin", But we copied all files to build in the main project. 
POM of the source package
2. We use a "Maven Assembly Plugin" to pack all a project and all dependencies from (1) to build a fat jar file.“Maven Assembly Plugin” is bind to the Maven’s packaging phase, to process to the final jar.So, the build command is "mvn clean install"
POM of the main project

Why call a “FAT JAR” ?

The Qualifiers (in increasing order of logical size):

  • Skinny — Contains ONLY the bits you literally type into your code editor, and NOTHING else.
  • Thin — Contains all of the above PLUS the app’s direct dependencies of your app (db drivers, utility libraries, etc).
  • Hollow — The inverse of Thin — Contains only the bits needed to run your app but does NOT contain the app itself. Basically a pre-packaged “app server” to which you can later deploy your app, in the same style as traditional Java EE app servers, but with important differences, we’ll get to later.
  • Fat/Uber — Contains the bit you literally write yourself PLUS the direct dependencies of your app PLUS the bits needed to run your app “on its own”.

The reference according to https://dzone.com/articles/the-skinny-on-fat-thin-hollow-and-uber

Nami Oyamada

Written by

Software developer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade