Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging Multiple Jars in to a Single Jar

Tags:

java

jar

my application needs multiple jars to work. Since it is a desktop application i can not hold the user responsible of installing. So in my build script i unzip the jars content in to my build directory delete manifest files, compile my software and jar it again. Everything works as it should my question is are there any long term side effects to this process?

like image 557
Hamza Yerlikaya Avatar asked May 19 '09 11:05

Hamza Yerlikaya


People also ask

How do I combine multiple jar files into one?

Just unzip both jar files, then zip the results into one zip file, and rename this to jar again. But as adarshr said: Better use the jar command for that. If you do that, you will lose or overwrite the MANIFEST.

What is Onejar?

sbt-onejar is a simple-build-tool plugin for building a single executable JAR containing all your code and dependencies as nested JARs. Currently One-JAR version 0.9. 7 is used.


1 Answers

In the past, there were JARs with weird content (like the DB2 driver which contains com.ibm and com.IBM; after decompressing in a Windows filesystem, those two packages would be merged).

The only issue you need to be aware of are signed jars and other files in META-INF which might have the same name in multiple source JARs.

A simple solution for all these issues is to use One-JAR. It allows to wrap several JARs into one without unpacking them, first. And read this answer: Easiest way to merge a release into one JAR file

like image 96
Aaron Digulla Avatar answered Sep 30 '22 17:09

Aaron Digulla