0

Let's take the following exemple: build a library A that has 3 dependencies X, Y, Z and we create 2 JARs: regular and FAT.

We have a service B in which we first import the normal JAR and then the FAT jar.

  1. In the first case (regular JAR) will we need to manually import all the dependencies (X, Y, Z) in B so that A works (importing the JAR of A will not automatically import all its transitive(direct) dependencies - X, Y, Z) ? / OR / the library will work (calling it's methods) but trying to call methods from X, Y, Z will fail and we will need to manually import them ?
  2. In the second scenario because the Fat JAR has all the dependencies imbedded we won't need to add any dependencies right ? We can both use A and also methods and classes from X, Y and Z.

Is what I said at 1) and 2) right ? Is this how it works ?

Runtime Classpath vs Compile Classpath for normal vs FAT JAR

  1. Including the normal JAR of A as a dependency to B:
  • compile classpath will only have A dependency ?
  • runtime classpath will have A, X, Y and Z dependencies ?
  1. Including the FAT JAR of A as a dependency to B:
  • compile classpath will have A, X, Y and Z dependencies ?
  • runtime classpath will have A, X, Y and Z dependencies ?

Is this how the compile classpath and runtime classpath will look like in these scenarios ?

Stefan Ss
  • 45
  • 5
  • Is library A going to be used by another library or application? It is probably a bad idea to use fat jars. The sub dependencies versions may conflict. Fat jars are usually used for application jars to include all their dependencies. – aled Aug 01 '23 at 19:20
  • Ok understood, but that's not answering my questions. Could you also tell me if what i wrote above is right or not? – Stefan Ss Aug 01 '23 at 19:24

1 Answers1

0

Yes, your understanding is correct.

In summary, regular JARs require you to manage the dependencies manually, while FAT JARs (or UBER JARs) bundle all the dependencies together, making it more convenient for distribution and deployment as it reduces the need to manage separate JAR files for each dependency.

However, it's worth noting that using FAT JARs can lead to larger JAR sizes, which might be a concern in certain scenarios.

Check this out:

Diego Borba
  • 1,282
  • 8
  • 22