JAR (file format)
Encyclopedia
In software, JAR is an archive file format typically used to aggregate many Java class files and associated metadata
and resources (text, images and so on) into one file to distribute application software
or libraries on the Java platform.
JAR files are built on the ZIP file format and have the
. They can also use
A JAR file has an optional manifest file
located in the path
Main-Class: myPrograms.MyClass
Users can typically start such JAR files with a command similar to:
To unzip a JAR file users can use any standard unzip software. However, anyone with an installed Java Virtual Machine
can use the jar command to expand the file:
These files can also include a Classpath
entry, which identifies other JAR files for loading 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.
Developers can digitally 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 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.
Developers can obfuscate
JAR files 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 devolpment
Microsoft Windows
users who prefer having Windows EXE
files can use tools such as JSmooth
, Launch4J, WinRun4J or Nullsoft Scriptable Install System
to wrap JAR files into executables.
build tool has its own package to read and write Zip and JAR archives, including support for the Unix
filesystem extensions. The org.apache.tools.zip package is released under the Apache Software Foundation
license and is designed to be usable outside Ant.
Metadata
The term metadata is an ambiguous term which is used for two fundamentally different concepts . Although the expression "data about data" is often used, it does not apply to both in the same way. Structural metadata, the design and specification of data structures, cannot be about data, because at...
and resources (text, images and so on) into one file to distribute application software
Application software
Application software, also known as an application or an "app", is computer software designed to help the user to perform specific tasks. Examples include enterprise software, accounting software, office suites, graphics software and media players. Many application programs deal principally with...
or libraries on the Java platform.
JAR files are built on the ZIP file format and have the
.jar
file extension. Computer users can create or extract JAR files using the jar
command that comes with a JDKJava Development Kit
The Java Development Kit is an Oracle Corporation product aimed at Java developers. Since the introduction of Java, it has been by far the most widely used Java SDK. On 17 November 2006, Sun announced that it would be released under the GNU General Public License , thus making it free software...
. They can also use
zip
tools to do so; however, the order of entries in the zip file headers is important when compressing, as the manifest often needs to be first.Design
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. The packagejava.util.zip
contains classes that read and write JAR files.A JAR file has an optional manifest file
Manifest file
On the Java platform, a Manifest file is a specific file contained within a JAR archive. It is used to define extension and package-related data. It is a metadata file that contains name-value pairs organized in different sections. If a JAR file is intended to be used as an executable file, the...
located in the path
META-INF/MANIFEST.MF
. The entries in the manifest file determine how one can use the JAR file. JAR files 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 asMain-Class: myPrograms.MyClass
Users can typically start such JAR files with a command similar to:
java -jar foo.jar
To unzip a JAR file users can use any standard unzip software. However, anyone with an installed Java Virtual Machine
Java Virtual Machine
A Java virtual machine is a virtual machine capable of executing Java bytecode. It is the code execution component of the Java software platform. Sun Microsystems stated that there are over 4.5 billion JVM-enabled devices.-Overview:...
can use the jar command to expand the file:
jar -xf foo.jar
These files can also include a Classpath
Classpath (Java)
Classpath is a parameter—set either on the command-line, or through an environment variable—that tells the Java Virtual Machine or the compiler where to look for user-defined classes and packages.-Overview and architecture:...
entry, which identifies other JAR files for loading 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.
Developers can digitally sign
Digital signature
A digital signature or digital signature scheme is a mathematical scheme for demonstrating the authenticity of a digital message or document. A valid digital signature gives a recipient reason to believe that the message was created by a known sender, and that it was not altered in transit...
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 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.
Developers can obfuscate
Obfuscated code
Obfuscated code is source or machine code that has been made difficult to understand for humans. Programmers may deliberately obfuscate code to conceal its purpose or its logic to prevent tampering, deter reverse engineering, or as a puzzle or recreational challenge for someone reading the source...
JAR files 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 devolpment
Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
users who prefer having Windows EXE
EXE
EXE is the common filename extension denoting an executable file in the DOS, OpenVMS, Microsoft Windows, Symbian, and OS/2 operating systems....
files can use tools such as JSmooth
JSmooth
JSmooth is a tool for wrapping Java JAR files into Windows Portable Executable EXE files. It allows specifying various details on how the program should be invoked, such as:* Executable icon* Program arguments...
, Launch4J, WinRun4J or Nullsoft Scriptable Install System
Nullsoft Scriptable Install System
Nullsoft Scriptable Install System is a script-driven Windows installation system with minimal overhead backed by Nullsoft, the creators of Winamp...
to wrap JAR files into executables.
Apache Ant Zip/JAR support
The Apache AntApache Ant
Apache Ant is a software tool for automating software build processes. It is similar to Make but is implemented using the Java language, requires the Java platform, and is best suited to building Java projects....
build tool has its own package to read and write Zip and JAR archives, including support for the Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...
filesystem extensions. The org.apache.tools.zip package is released under the Apache Software Foundation
Apache Software Foundation
The Apache Software Foundation is a non-profit corporation to support Apache software projects, including the Apache HTTP Server. The ASF was formed from the Apache Group and incorporated in Delaware, U.S., in June 1999.The Apache Software Foundation is a decentralized community of developers...
license and is designed to be usable outside Ant.
Related formats
Several related file formats build on the JAR format:- WAR (Web application archive) files, also Java archives, store XMLXMLExtensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....
files, Java classes, JavaServer PagesJavaServer PagesJavaServer Pages is a Java technology that helps software developers serve dynamically generated web pages based on HTML, XML, or other document types...
and other objects for Web Applications. - RAR (resource adapter archive) files (not to be confused with the RAR file format), also Java archives, store XMLXMLExtensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....
files, Java classes and other objects for J2EE Connector Architecture (JCA) applications. - EAREAR (file format)EAR is a file format used by Java EE for packaging one or more modules into a single archive so that the deployment of the various modules onto an application server happens simultaneously and coherently...
(enterprise archive) files provide composite Java archives which combine XMLXMLExtensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....
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.
- APKAPK (file format)Android application package file is the file format used to distribute and install application software and middleware onto the Google's Android operating system. To make an APK file, a program for Android is first compiled, and then all of its parts are packaged into one file...
(Android Application Package), a variant of the Java archive format, is used for Android applications.