Unojar Maven Plugin

Unojar maven plugin creates a "fat jar" or "uber jar". It packages dependency jars with a main jar file, and with a specified main class to start, into a ...unojar.jar file. Dependent jars are automatically loaded with the main jar, and main method in the main class is called. This allows an entire application to be released as a single file and run with "java -jar ...unojar.jar".

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

org.greening
ArtifactId

ArtifactId

unojar-maven-plugin
Last Version

Last Version

1.5.0
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

Unojar Maven Plugin
Unojar maven plugin creates a "fat jar" or "uber jar". It packages dependency jars with a main jar file, and with a specified main class to start, into a ...unojar.jar file. Dependent jars are automatically loaded with the main jar, and main method in the main class is called. This allows an entire application to be released as a single file and run with "java -jar ...unojar.jar".
Project URL

Project URL

https://github.com/greening/unojar-maven-plugin
Source Code Management

Source Code Management

https://github.com/greening/unojar-maven-plugin

Download unojar-maven-plugin

How to add to project

<plugin>
    <groupId>org.greening</groupId>
    <artifactId>unojar-maven-plugin</artifactId>
    <version>1.5.0</version>
</plugin>

Dependencies

compile (8)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.30
com.needhamsoftware.unojar : core jar 1.0.1
commons-io : commons-io jar 2.7
org.apache.maven : maven-model jar 3.6.3
org.apache.maven : maven-core jar 3.6.3
org.apache.maven : maven-plugin-api jar 3.6.3
org.apache.maven : maven-artifact jar 3.6.3
org.apache.maven : maven-project jar 2.2.1

provided (1)

Group / Artifact Type Version
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.6.0

test (4)

Group / Artifact Type Version
org.apache.maven.plugin-testing : maven-plugin-testing-harness jar 3.3.0
org.apache.maven : maven-resolver-provider jar 3.6.3
org.apache.maven : maven-compat jar 3.6.3
org.junit.jupiter : junit-jupiter-engine jar 5.6.2

Project Modules

There are no modules declared in this project.

unojar-maven-plugin

Build an executable jar containing all dependencies as internal, intact jar files. This means you can ship one jar file with all the libraries included.

There are various alternatives out there, including

  • maven-shade-plugin, which unpacks libraries and includes them in an uber-jar. By doing this, you lose the modularity of the jars.
  • Capsule is now defunct, but the linked article has a useful critique of One-Jar
  • SlimFast (for deploying jar artifacts on AWS S3)
  • Spring Boot ... if you are using Spring.
  • Messing with the maven-assembly-plugin, but that will just unpack all dependencies together with your classes in one directory and then repack that directory into a new jar. Doing it that way means files will overwrite each other if they have the same names in the same path, which is quite common with resources such as log4.properties and even other more important files.

With unojar-maven-plugin, you'll instead get a nice clean super jar with the dependency jars inside.

Get started by following the Usage instructions!

The fork packages a patched one-jar 0.97 from iceberg901 and uses that version by default. The original 0.97 is still intact and can be used by specifying the bootfile configuration option in the maven pom.xml.

Example pom.xml plugin configuration

<build>
    <plugins>
        <plugin>
            <groupId>org.greening</groupId>
            <artifactId>unojar-maven-plugin</artifactId>
            <version>1.5.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>unojar</goal>
                    </goals>
                    <configuration>
                        <mainClass>my.package.Foo</mainClass>
                        <attachToBuild>true</attachToBuild>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Plugin Developers

If you'd like to make changes I'm happy to review and merge pull requests. The intention is that each release should make the source cleaner, so please emphasize smaller code, exploit new features in OpenJava 11 (the latest LTS release), and add clear documentation for whatever you might provide.

Challenges

I'll just mention here things that didn't work well for me, so you can either avoid them or think of them as "for the mightiest," such as you.

  • I believe because the the org.apache.maven:plugin-testing source code is not being maintained, I could not get Maven Plugin Test Harness to work. There is a test Mojo in the unojar-maven-plugin source code that is useful.
  • The MANIFEST.MF file in the fatjar has extra stuff in it. There's probably a way to figure out whether you should put out a One-Jar-Main-Class entry (only when you use one-jar) or a Uno-Jar-Main-Class entry (when you use uno-jar), but at present this version provides both in MANIFEST.MF. If you tackle this, remember that a user can supply the boot file separately, so you might want to look in the boot file manifest to figure out which one to use.
  • There's an ImplementationVersion and an Implementation-Version entry in the MANIFEST.MF file. Do we need both?

References

Plugin Deployers

Only Dan at the moment. Contribute something useful and I'll make you one.

Versions

Version
1.5.0