JAR (file format)

In computing, a JAR file (or Java ARchive) is used for aggregating many files into one. It is generally used to distribute Java classes and associated metadata.

JAR files can be created and extracted using the "jar" command that comes with the JDK. It can be done using zip tools, but as WinZip has a habit of renaming all-uppercase directories and files in lower case, this can raise support calls with whoever created the JAR or the tool authors themselves. WinRAR, on the other hand, retains the original case of filenames.

A JAR file has an optional manifest file located in the path META-INF/MANIFEST.MF. The entries in the manifest file determine how the JAR file will be used. JAR files which are intended to be executed as standalone programs will have one of their classes specified as the "main" class. The manifest file would have an entry such as

These files can also include a Classpath entry, which identifies other JAR files to be loaded with the JAR. This entry consists of a list of absolute or relative paths to other JAR files. Although intended to simplify JAR use, in practice, it turns out to be notoriously brittle as it depends on all the relevant JARs being in the exact locations specified when the entry-point JAR was built. To change versions or locations of libraries, a new manifest is needed.

A JAR file can be digitally signed. If so, the signature information is added to the manifest file. The JAR itself is not signed, but instead every file inside the archive is listed along with its checksum; it is these checksums that are signed. Multiple entities may sign the JAR file, changing the JAR file itself with each signing -but the signed files themselves remain valid. When the Java runtime loads signed JAR files, it can validate the signatures and refuse to load classes that do not match the signature. It can also support 'sealed' packages, in which the classloader will only permit Java classes to be loaded into the same package if they are all signed by the same entities. This prevents malicious code from being inserted into an existing package, and so gain access to package-scoped classes and data.

JAR files can be obfuscated so that a user of the JAR file doesn't get much information regarding the code it contains, or to reduce its size, which is useful in mobile phone applications.

For those Microsoft Windows users who prefer having Windows EXE files, tools such as JSmooth or Launch4J can be used to wrap JAR files into executables. Eclipse uses a small EXE launcher (eclipse.exe) to display the splash screen on startup and launch the application from the main JAR (startup.jar).