I am reading Maven documentation and came across the nameuber-jar
.
What does anuber-jar
mean and what are its features/advantages?
- 2I have also occasionally seen it called a "onejar" or "one-jar".CommentedDec 6, 2016 at 1:36
- 2"uber" anything - unless in German, a concept named by an illiterate fool.CommentedJun 29, 2023 at 23:24
7 Answers7
Über
is the German word forabove
orover
(it's actually cognate with the Englishover
).
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 packageand 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 actuallyhas no dependencies.
All the dependencies of your own stuff within the uber-jar arealso within that uber-jar. As are all dependencies of those dependencies. And so on.
(a) I probablyshouldn'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.
- 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 ;-)– BjoernCommentedMar 5, 2015 at 18:09
- 43BTW,
über
andover
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.– biziclopCommentedJun 26, 2015 at 18:57 - 1Given how much grief I've gotten about trying toeducate 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 :-)CommentedFeb 20, 2020 at 13:32
- 9Me: Reads "history lesson". Me: Opens revision history to read it. :-)CommentedJan 4, 2021 at 16:06
Fromimagej.net Uber-JAR description:
Anuber JAR file is also known asfat JAR, i.e., aJAR filewith dependencies.
There are three common methods for constructing an uber JAR file:
- Unshaded: Unpack all JAR files, and then repack them into a single JAR file. It works with Java's default class loader. Toolsmaven-assembly-plugin
- Shaded: Same as unshaded, but rename (i.e., "shade") allpackages of all dependencies. It works with Java's default class loader. It avoids some (not all) dependency version clashes. Toolsmaven-shade-plugin
- JAR files of JAR files: The final JAR file contains the other JAR files embedded within. It avoids dependency version clashes. Allresource files are preserved. Tools:Eclipse JAR File Exporter
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:
- basically withmaven-assembly-plugin
- a bit more further withmaven-shade-plugin
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 (withMaven and its plugin).
Finally, a really good solution is to use anOSGi Bundle. There are plenty of good tutorials on that :)
For further configuration, please read those topics:
The different names are just ways of packaging Java applications.
Skinny – Containsonly the bits you literally type into your code editor, andnothing else.
Thin – Contains all of the aboveplus 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 doesnot 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 yourselfplus the direct dependencies of your applicationplus the bits needed to run your application “on its own”.
Source:Article from Dzone
Reposted from:What is a fat JAR?
- '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?– mariboxCommentedDec 21, 2022 at 16:13
- @MySurmise You still need to have Java/JVM/JRE installed.CommentedJun 21, 2023 at 1:18
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
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.
For Java Developers who use SpringBoot,ÜBER/FAT JAR isnormally the final result of thepackage phase
of maven (orbuild task
if you usegradle
).
Inside the Fat JAR one can find aMETA-INF
directory inside which theMANIFEST.MF
file lives with all the info regarding the Main class. More importantly, at the same level ofMETA-INF
directory you find theBOOT-INF
directory inside which the directorylib
lives and contains all the.jar
files that are the dependencies of your application.
Explore related questions
See similar questions with these tags.