JAR file (or Java ARchive) aggregates many files into one. JAR files build on the ZIP file format.
A jar file allows java runtimes to efficiently deploy a set of classes and their associated resources. The elements in a JAR file can be compressed, which, together with the ability to download an entire application in a single request, makes downloading a JAR file much faster than separately downloading the many uncompressed files which would form a single Java Application. External libraries for Java language are very often represented as JAR files too. The package java.util.jar
contains classes that read and write JAR files.
JAR file usually contains a manifest file - /META-INF/MANIFEST.MF
. Manifest can contain additional meta information about the packaged code, such as version note, package vendor, packaging utility (e.g. ant or maven) used to build the package, implemented specification reference and so on. For executable JAR file manifest is mandatory.
JAR files can also be signed with a certificate to prevent unathorized modification. For Java applets and Java Web Start applications a proper JAR signature is quite important, as modern browsers won't trust unsigned or self-signed Java applications. Oracle jarsigner tool can be used for both JAR signing and signature verification.
Proper MIME type for JAR file is "application/java-archive".
To run your JAR file use: java -jar YourApp.jar
Frequently Asked Questions
People often ask these questions about this topic:
- Running JAR file on Windows
- How to get the path of a running JAR file?
- How should I load Jars dynamically at runtime?
- How do I list the files inside a JAR file?
- How can an app use files inside the JAR for read and write?
- How to import a jar in Eclipse
- How do I read a resource file from a Java jar file?