JAR File
   HOME

TheInfoList



OR:

A JAR ("Java archive") file is a package
file format A file format is a Computer standard, standard way that information is encoded for storage in a computer file. It specifies how bits are used to encode information in a digital storage medium. File formats may be either proprietary format, pr ...
typically used to aggregate many
Java class file A Java class file is a file (with the filename extension) containing Java bytecode that can be executed on the Java Virtual Machine (JVM). A Java class file is usually produced by a Java compiler from Java programming language source files ...
s and associated
metadata Metadata (or metainformation) is "data that provides information about other data", but not the content of the data itself, such as the text of a message or the image itself. There are many distinct types of metadata, including: * Descriptive ...
and resources (text, images, etc.) into one file for distribution. JAR files are
archive file In computing, an archive file stores the content of one or more files, possibly compressed, with associated metadata such as file name, directory structure, error detection and correction information, commentary, compressed data archives, sto ...
s that include a Java-specific
manifest file In computer programming, a manifest file is a Data file, file containing metadata for a group of accompanying files that are part of a set or coherent unit. For example, the files of a computer program may have a manifest describing the name, Soft ...
. They are built on the ZIP format and typically have a .jar
file extension File or filing may refer to: Mechanical tools and processes * File (tool), a tool used to remove fine amounts of material from a workpiece. ** Filing (metalworking), a material removal process in manufacturing ** Nail file, a tool used to gen ...
.


Design

A JAR file allows Java runtimes to efficiently deploy an entire application, including its classes and their associated resources, in a single request. JAR file elements may be compressed, shortening download times. A JAR file may contain a manifest file, that is located at META-INF/MANIFEST.MF. The entries in the manifest file describe how to use the JAR file. For instance, a
Classpath Classpath is a parameter in the Java Virtual Machine or the Java compiler that specifies the location of user-defined classes and packages. The parameter may be set either on the command-line, or through an environment variable. Overview and ...
entry can be used to specify other JAR files to load with the JAR.


Extraction

The contents of a file may be extracted using any archive extraction software that supports the ZIP format, or the jar command line utility provided by the Java Development Kit.


Security

Developers can attributed sign JAR files. In that case, the signature information becomes part of the embedded 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, although 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 The Java class loader, part of the Java Runtime Environment, dynamically loads Java classes into the Java Virtual Machine. Usually classes are only loaded on demand. The virtual machine will only load the class files required for executing the prog ...
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 gaining access to package-scoped classes and data. The content of JAR files may be
obfuscated Obfuscation is the obscuring of the intended meaning of communication by making the message difficult to understand, usually with confusing and ambiguous language. The obfuscation might be either unintentional or intentional (although intent u ...
to make
reverse engineering Reverse engineering (also known as backwards engineering or back engineering) is a process or method through which one attempts to understand through deductive reasoning how a previously made device, process, system, or piece of software accompl ...
more difficult.


Executable JAR files

An executable Java program can be packaged in a JAR file, along with any libraries the program uses. Executable JAR files have the manifest specifying the
entry point In computer programming, an entry point is the place in a program where the execution of a program begins, and where the program has access to command line arguments. To start a program's execution, the loader or operating system passes co ...
class with Main-Class: myPrograms.MyClass and an explicit Class-Path (and the -cp argument is ignored). Some operating systems can run these directly when clicked. The typical invocation is java -jar foo.jar from a command line. Native launchers can be created on most platforms. For instance, Microsoft Windows users who prefer having Windows
EXE Exe or EXE may refer to: * .exe, a file extension * exe., abbreviation for Executive (disambiguation)#Role, title, or function, executive Places * River Exe, in England * Exe Estuary, in England * Exe Island, in Exeter, England Transportation a ...
files can use tools such as JSmooth, Launch4J, WinRun4J or
Nullsoft Scriptable Install System Nullsoft, Inc. was an American software house founded in Sedona, Arizona in 1997 by programmer Justin Frankel. Its products included the Winamp media player and the SHOUTcast MP3 streaming media server. History In 1997, Justin Frankel, ...
to wrap single JAR files into executables.


Manifest

A manifest file is a
metadata Metadata (or metainformation) is "data that provides information about other data", but not the content of the data itself, such as the text of a message or the image itself. There are many distinct types of metadata, including: * Descriptive ...
file contained within a JAR. It defines extension and package-related data. It contains
name–value pair A name–value pair, also called an attribute–value pair, key–value pair, or field–value pair, is a fundamental data representation in computing systems and applications. Designers often desire an open-ended data structure that allows fo ...
s organized in sections. If a JAR file is intended to be used as an executable file, the manifest file specifies the main class of the application. The manifest file is named MANIFEST.MF. The manifest directory has to be the first entry of the compressed archive.


Specifications

The manifest appears at the
canonical The adjective canonical is applied in many contexts to mean 'according to the canon' the standard, rule or primary source that is accepted as authoritative for the body of knowledge or literature in that context. In mathematics, ''canonical exampl ...
location META-INF/MANIFEST.MF. There can be only one manifest file in an archive and it must be at that location. The content of the manifest file in a JAR file created with version 1.0 of the
Java Development Kit The Java Development Kit (JDK) is a distribution of Java technology by Oracle Corporation. It implements the Java Language Specification (JLS) and the Java Virtual Machine Specification (JVMS) and provides the Standard Edition (SE) of the Java ...
is the following. Manifest-Version: 1.0 The name is separated from its value by a colon. The default manifest shows that it conforms to version 1.0 of the manifest specification. The manifest can contain information about the other files that are packaged in the archive. Manifest contents depend on the intended use for the JAR file. The default manifest file makes no assumptions about what information it should record about other files, so its single line contains data only about itself. It should be encoded in UTF-8.


Special-Purpose Manifest Headers

JAR files created only for the purpose of archiving do not use the MANIFEST.MF file. Most uses of JAR files go beyond simple archiving and compression and require special information in the manifest file.


Features

The manifest allows developers to define several useful features for their jars. Properties are specified in key-value pairs.


Applications

If an application is contained in a JAR file, the
Java Virtual Machine A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally descr ...
needs to know the application's entry point. An entry point is any class with a public static void main(String[] args) method. This information is provided in the manifest Main-Class header, which has the general form: Main-Class: com.example.MyClassName In this example com.example.MyClassName.main() executes at application launch.


Package Sealing

Optionally, a package within a JAR file can be sealed, which means that all classes defined in that package are archived in the same JAR file. A package might be sealed to ensure version consistency among the classes in the software or as a security measure. To seal a package, a Name entry needs to appear, followed by a Sealed header, such as: Name: myCompany/myPackage/ Sealed: true The Name header's value is the package's relative pathname. Note that it ends with a '/' to distinguish it from a filename. Any headers following a Name header, without any intervening blank lines, apply to the file or package specified in the Name header. In the above example, because the Sealed header occurs after the Name: myCompany/myPackage header with no intervening blank lines, the Sealed header applies (only) to the package myCompany/myPackage. The feature of sealed packages is outmoded by the Java Platform Module System introduced in Java 9, in which modules cannot split packages.


Package Versioning

Several manifest headers hold versioning information. One set of headers can be assigned to each package. The versioning headers appear directly beneath the Name header for the package. This example shows all the versioning headers: Name: java/util/ Specification-Title: "Java Utility Classes" Specification-Version: "1.2" Specification-Vendor: "Sun Microsystems, Inc.". Implementation-Title: "java.util" Implementation-Version: "build57" Implementation-Vendor: "Sun Microsystems, Inc."


Multi-Release

A jar can be optionally marked as a multi-release jar. Using the multi-release feature allows library developers to load different code depending on the version of the Java runtime. This in turn allows developers to leverage new features without sacrificing compatibility. A multi-release jar is enabled using the following declaration in the manifest: Multi-Release: true


Dependencies

The MANIFEST.MF file can be used to specify all the classes that must be loaded for an application to be able to run. Note that Class-Path entries are delimited with spaces, not with the system path delimiter: Class-Path: . pkg1.jar path/to/pkg2.jar


Apache Ant Zip/JAR support

The
Apache Ant Apache Ant is a software tool for automating software build processes for Java applications which originated from the Apache Tomcat project in early 2000 as a replacement for the Make build tool of Unix. It is similar to Make, but is implement ...
build tool has its own package to read and write Zip and JAR archives, including support for
Unix Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
filesystem extensions. The org.apache.tools.zip package is released under the
Apache Software Foundation The Apache Software Foundation ( ; ASF) is an American nonprofit corporation (classified as a 501(c)(3) organization in the United States) to support a number of open-source software projects. The ASF was formed from a group of developers of the ...
license and is designed to be usable outside Ant.


Related formats

Several related file formats build on the JAR format: *
WAR War is an armed conflict between the armed forces of states, or between governmental forces and armed groups that are organized under a certain command structure and have the capacity to sustain military operations, or between such organi ...
(Web application archive) files, also Java archives, store
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
files, Java classes,
JavaServer Pages Jakarta Server Pages (JSP; formerly JavaServer Pages) is a collection of technologies that helps software developers create dynamically generated web pages based on HTML, XML, SOAP, or other document types. Released in 1999 by Sun Microsystems, J ...
and other objects for Web Applications. * RAR (resource adapter archive) files (not to be confused with the RAR file format), also Java archives, store XML files, Java classes and other objects for J2EE Connector Architecture (JCA) applications. *
EAR In vertebrates, an ear is the organ that enables hearing and (in mammals) body balance using the vestibular system. In humans, the ear is described as having three parts: the outer ear, the middle ear and the inner ear. The outer ear co ...
(enterprise archive) files provide composite Java archives that combine XML files, Java classes and other objects including JAR, WAR and RAR Java archive files for Enterprise Applications. * SAR (service archive) is similar to EAR. It provides a service.xml file and accompanying JAR files. * APK (Android application package), a variant of the Java archive format, is used for Android applications. *
AAR The Aare () or Aar () is the main tributary of the High Rhine (its discharge even exceeds that of the latter at their confluence) and the longest river that both rises and ends entirely within Switzerland. Its total length from its source to i ...
(Android archive) is used for distribution of Android libraries, typically via
Maven MAVEN is a NASA spacecraft orbiting Mars to study the loss of that planet's atmospheric gases to space, providing insight into the history of the planet's climate and water. The name is an acronym for "Mars Atmosphere and Volatile Evolution" w ...
. * PAR (plan archive) – supported by Eclipse Virgo
OSGi OSGi is an open specification and open source project under the Eclipse Foundation. It is a continuation of the work done by the OSGi Alliance (formerly known as the Open Services Gateway initiative), which was an open standards organization fo ...
application server, allows the deployment of multi-bundle OSGi applications as a single archive and provides isolation from other PAR-based applications deployed in the same server. * KAR (Karaf archive) – supported by Apache Karaf OSGi application server, allows the deployment of multi-bundle, multi-feature OSGi applications.


See also

*
JAR hell The Java class loader, part of the Java Runtime Environment, dynamically loads Java classes into the Java Virtual Machine. Usually classes are only loaded on demand. The virtual machine will only load the class files required for executing the prog ...
*
Java Platform Module System The Java Platform Module System specifies a distribution format for collections of Java code and associated resources. It also specifies a repository for storing these collections, or '' modules'', and identifies how they can be discovered, loaded ...
*
Open Packaging Conventions The Open Packaging Conventions (OPC) is a container-file technology initially created by Microsoft to store a combination of XML and non-XML files that together form a single entity such as an Open XML Paper Specification (OpenXPS) document. OPC- ...
*
JAD (file format) Java Application Descriptor (JAD) files describe the MIDlets (Java ME applications) that are distributed as JAR (file format), JAR files. JAD files are commonly used to package Java (programming language), Java applications or games that can be d ...
* GIFAR attack * .a static libraries


References


External links


JAR File Specification


{{Compression Software Implementations Archive formats Java platform