Java – Difference between extracting and packaging libraries into a jar file


I would like to know the difference between extracting and packaging libraries into a jar file from eclipse with the runnable jar file creation.

If my program (runnable jar) uses other classes which require these external libraries(jars), what should I pick?

Best Solution

If you want to put jars into your generated jar file, you can use packaging method. For example if you are using an Apache library or some other 3rd party jars, you may want to keep these jars preserved in your generated jar. In this case, use packaging. "Packaging required libraries into a jar file" option puts classes of org.eclipse.jdt.internal.jarinjarloader package into your generated file and this package is just under the root directory of the generated jar file. This option also creates a larger jar file in terms of size due to jar loader classes of Eclipse.

Extracting required libraries will result in putting classes of 3rd party libraries into your jar file by following the package naming convention, e.g. if you open your jar content you can see some classes under org.apache.. packages.

Main class entries are different between the MANIFEST.MF files of these jar files:

Main class entry when you package required libraries:

Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader

Main class entry when you extract required libraries:

Main-Class: YourMainClass