Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you add multiple jars in a jar file and then launch that jar file

Tags:

java

jar

I am working on a GUI application and would rather distribute just one jar as opposed to multiple ones.

Can you control this with the manifest.

like image 677
Berlin Brown Avatar asked Feb 10 '09 07:02

Berlin Brown


People also ask

Can a JAR file contain another JAR file?

To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar. jar contains another JAR file called MyUtils. jar, you cannot use the Class-Path header in MyJar.

What is multi Release JAR?

A multi-release JAR file allows for a single JAR file to support multiple major versions of Java platform releases. For example, a multi-release JAR file can depend on both the Java 8 and Java 9 major platform releases, where some class files depend on APIs in Java 8 and other class files depend on APIs in Java 9.

How do I specify multiple JARs in classpath?

In general, to include all of the JARs in a given directory, you can use the wildcard * (not *. jar ). The wildcard only matches JARs, not class files; to get all classes in a directory, just end the classpath entry at the directory name.


3 Answers

Another option is to use a custom class loader such as this one:

http://one-jar.sourceforge.net/

like image 160
Sam Avatar answered Oct 20 '22 06:10

Sam


Merge your jars to one jar. See this thread.

like image 26
trunkc Avatar answered Oct 20 '22 05:10

trunkc


You need to be careful when doing this. If the jars you are merging have manifest files with critical information - these can get lost, only the last file will get merged.

E.g. If you merge JavaMail - the manifest file is important. If you lose it - bad things csn happen.

The safest thing to do is to look at each jar file and check the manifest file.

like image 21
Fortyrunner Avatar answered Oct 20 '22 04:10

Fortyrunner