What is an uber JAR file?
Asked Answered
S

7

379

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

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

Snowclad answered 14/8, 2012 at 6:42 Comment(2)
I have also occasionally seen it called a "onejar" or "one-jar".Warthog
"uber" anything - unless in German, a concept named by an illiterate fool.Vachil
C
509

Ü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.

Chopine answered 14/8, 2012 at 6:46 Comment(6)
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 ;-)Drank
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.Hickson
Very smart description: Example linkHaith
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 :-)Chopine
Me: Reads "history lesson". Me: Opens revision history to read it. :-)Greggs
Muito boa sua explicação!Milo
U
123

From imagej.net Uber-JAR description:

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
Unhelm answered 19/8, 2016 at 3:27 Comment(0)
M
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:

Mervin answered 14/8, 2012 at 14:12 Comment(0)
F
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?

Fruin answered 18/5, 2020 at 17:11 Comment(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?Singlehandedly
@Singlehandedly You still need to have Java/JVM/JRE installed.Orelle
C
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

Chaudfroid answered 3/5, 2017 at 12:46 Comment(0)
L
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.

Lexington answered 28/6, 2020 at 10:21 Comment(0)
F
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.

Filial answered 22/8, 2020 at 18:49 Comment(1)
the same for gradleMustee

© 2022 - 2024 — McMap. All rights reserved.