Ashay Batwal
Ashay Batwal

Reputation: 5613

What is an uber JAR file?

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

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

Upvotes: 383

Views: 156902

Answers (7)

anon
anon

Reputation:

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

Upvotes: 125

Jean-Rémy Revy
Jean-Rémy Revy

Reputation: 5677

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:

Upvotes: 64

Mark Han
Mark Han

Reputation: 3145

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?

Upvotes: 24

Davide Martorana
Davide Martorana

Reputation: 729

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.

Upvotes: 1

Md. Jamal Uddin
Md. Jamal Uddin

Reputation: 792

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.

Upvotes: 1

paxdiablo
paxdiablo

Reputation: 881643

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

Upvotes: 518

Rasheed
Rasheed

Reputation: 1051

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

Upvotes: 4

Related Questions