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?
A package is a mechanism in Java for organizing classes into namespaces. A jar is a Java ARchive, a file that aggregates multiple Java classes into one.
A JAR file lets you physically organize your classes. You can take any Java files and store them in a JAR file. A JAR file may contain multiple packages, and multiple JAR files may contain files that belong to the same package. So, a JAR file is largely a way to store multiple class files in a single physical file.
The JVM is capable of loading classes or files from a jar file without extracting the jar to temp files. This functionality is also available to you in the standard library, see the JarFile for more information. So no, the JVM does not extract a jar to temp files, classes (and resources) are simply loaded on demand.
JAR Packaging Simply put, JAR – or Java Archive – is a package file format. JAR files have the . jar extension and may contain libraries, resources, and metadata files. Essentially, it's a zipped file containing the compressed versions of . class files and resources of compiled Java libraries and applications.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With