368

I am reading Maven documentation and came across the name uber-jar.

What does an uber-jar mean and what are its features/advantages?

2
  • 2
    I have also occasionally seen it called a "onejar" or "one-jar". Dec 6, 2016 at 1:36
  • "uber" anything - unless in German, a concept named by an illiterate fool.
    – Arfur Narf
    Jun 29 at 23:24

7 Answers 7

502

Über is the German word for above or over (it's actually cognate with the English over).

Hence, in this context, an uber-jar is an "over-jar", one level up from a simple JAR (a), defined as one that contains both your package and all its dependencies in one single JAR file. The name can be thought to come from the same stable as ultrageek, superman, hyperspace, and metadata, which all have similar meanings of "beyond the normal".

The advantage is that you can distribute your uber-jar and not care at all whether or not dependencies are installed at the destination, as your uber-jar actually has no dependencies.

All the dependencies of your own stuff within the uber-jar are also within that uber-jar. As are all dependencies of those dependencies. And so on.


(a) I probably shouldn't have to explain what a JAR is to a Java developer but I'll include it for completeness. It's a Java archive, basically a single file that typically contains a number of Java class files along with associated metadata and resources.

5
  • Strange... I am a german and of course know the word "über" and the meaning. But why is it used here in the Maven context? This case it means that one or more things are gathered together and is accessbile via the generated jar. Unfortunateley this hint didn't sovle my maven issue ;-)
    – Bjoern
    Mar 5, 2015 at 18:09
  • 37
    BTW, über and over are the result of a systematic vocal shift in Old Germanic which can also be observed in these word pairs: geben/give, leben/live, haben/have, heben/heave and many more.
    – biziclop
    Jun 26, 2015 at 18:57
  • Very smart description: Example link
    – Veniamin
    Dec 5, 2016 at 18:42
  • Given how much grief I've gotten about trying to educate people, I've decided to just remove the stuff that some keep complaining about. I still define uber in the context of the German language but the (somewhat verbose) history lesson is now gone :-)
    – paxdiablo
    Feb 20, 2020 at 13:32
  • 6
    Me: Reads "history lesson". Me: Opens revision history to read it. :-)
    – MC Emperor
    Jan 4, 2021 at 16:06
123

An uber JAR file is also known as fat JAR, i.e., a JAR file with dependencies.

There are three common methods for constructing an uber JAR file:

  1. Unshaded: Unpack all JAR files, and then repack them into a single JAR file. It works with Java's default class loader. Tools maven-assembly-plugin
  2. Shaded: Same as unshaded, but rename (i.e., "shade") all packages of all dependencies. It works with Java's default class loader. It avoids some (not all) dependency version clashes. Tools maven-shade-plugin
  3. JAR files of JAR files: The final JAR file contains the other JAR files embedded within. It avoids dependency version clashes. All resource files are preserved. Tools: Eclipse JAR File Exporter

For more

2
  • Concise and perfect!
    – Saran
    Feb 10 at 6:56
  • @Saran: Well, it was (almost) wholesale copied from the source, without any indication it wasn't the OP's own words. In other words, plagiarism. Jun 29 at 21:58
64

Paxdiablo's definition is really good.

In addition, please consider delivering an uber-jar is sometimes quite useful, if you really want to distribute a software and don't want customer to download dependencies by themselves. As a drawback, if their own policy don't allow usage of some library, or if they have to bind some extra-components (slf4j, system compliant libraries, architecture specialize libraries, ...) this will probably increase difficulties for them.

You can perform that:

A cleaner solution is to provide their library separately; maven-shade-plugin has a preconfigured descriptor for that. This is not more complicated to do (with Maven and its plugin).

Finally, a really good solution is to use an OSGi Bundle. There are plenty of good tutorials on that :)

For further configuration, please read those topics:

0
22

The different names are just ways of packaging Java applications.

Skinny – Contains only the bits you literally type into your code editor, and nothing else.

Thin – Contains all of the above plus the application’s direct dependencies of your applications (database drivers, utility libraries, etc.).

Hollow – The inverse of thin. It contains only the bits needed to run your application, but does not contain the application itself. Basically a pre-packaged “app server” to which you can later deploy your application, in the same style as traditional Java EE application servers, but with important differences.

Fat/Uber – Contains the bit you literally write yourself plus the direct dependencies of your application plus the bits needed to run your application “on its own”.

Source: Article from Dzone

Visual representation of JAR types

Reposted from: What is a fat JAR?

2
  • 'PLUS the bits needed to run your app “on its own”' Does that mean that I don't even need Java/JVM installed on the PC?
    – MySurmise
    Dec 21, 2022 at 16:13
  • @MySurmise You still need to have Java/JVM/JRE installed. Jun 21 at 1:18
4

A self-contained, executable Java archive. In the case of WildFly Swarm uberjars, it is a single .jar file containing your application, the portions of WildFly required to support it, an internal Maven repository of dependencies, plus a shim to bootstrap it all. see this

1

According to uber-JAR Documentation Approaches: There are three common methods for constructing an uber-JAR:

Unshaded Unpack all JAR files, then repack them into a single JAR. Tools: Maven Assembly Plugin, Classworlds Uberjar

Shaded Same as unshaded, but rename (i.e., "shade") all packages of all dependencies. Tools: Maven Shade Plugin

JAR of JARs The final JAR file contains the other JAR files embedded within. Tools: Eclipse JAR File Exporter, One-JAR.

1

For Java Developers who use SpringBoot, ÜBER/FAT JAR is normally the final result of the package phase of maven (or build task if you use gradle).

Inside the Fat JAR one can find a META-INF directory inside which the MANIFEST.MF file lives with all the info regarding the Main class. More importantly, at the same level of META-INF directory you find the BOOT-INF directory inside which the directory lib lives and contains all the .jar files that are the dependencies of your application.

1
  • the same for gradle
    – Black Bear
    Jul 17 at 13:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.