Jump to content

JAR (file format): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Reverting possible vandalism by 101.210.178.139 to version by Aberdeen01. False positive? Report it. Thanks, ClueBot NG. (1265610) (Bot)
mime type corrected with references
Line 4: Line 4:
| icon = [[Image:Nuvola mimetypes java jar.png|[[KDE]] JAR file icon]]
| icon = [[Image:Nuvola mimetypes java jar.png|[[KDE]] JAR file icon]]
| extension = <tt>.jar</tt>
| extension = <tt>.jar</tt>
| mime = application/java-archive<ref>{{cite web|title=File Extension .JAR Details|url=http://filext.com/file-extension/JAR|accessdate=29 November 2012}}</ref><ref>{{cite web|title=MIME : Java Glossary|url=http://mindprod.com/jgloss/mime.html|accessdate=29 November 2012}}</ref>
| mime = application/x-java-archive
| type code =
| type code =
| uniform type = com.sun.java-archive
| uniform type = com.sun.java-archive

Revision as of 11:01, 29 November 2012

Java Archive
KDE JAR file icon
Filename extension
.jar
Internet media type
application/java-archive[1][2]
Uniform Type Identifier (UTI)com.sun.java-archive
Developed byNetscape, Sun Microsystems, Oracle Corporation
Type of formatfile archive, data compression
Extended fromZIP

In software, JAR (Java ARchive) 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.[3]

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 JDK. 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 more convenient than separately downloading the many uncompressed files which would form a single Java Application. The package java.util.zip contains classes that read and write JAR files.

A JAR file has an optional manifest file located in the path META-INF/MANIFEST.MF. The entries in the manifest file determine how one can use the JAR file. For instance, a Classpath entry can be used to specify 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.

To extract the contents of a JAR file users can use any standard unzip software, or the jar command which comes with every Java Virtual Machine: "jar -xf foo.jar".

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 application development.

Executable JAR files

An executable Java program can be packaged in a JAR file, along with any libraries the program uses. Executable JAR files are distinguished by a 'extra field' on the first file with a hexadecimal field code of 0xCAFE.[4] In addition, the manifest must specify the "main" class, with an entry such as Main-Class: myPrograms.MyClass. On many operating systems, including Microsoft Windows, Solaris and most Linux distributions, these JAR files can be treated like any other executable file.[4] In any case, users can enter a command similar to "java -jar foo.jar".

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.

Apache Ant Zip/JAR support

The Apache Ant 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.

Related formats

Several related file formats build on the JAR format:

  • WAR (Web application archive) files, also Java archives, store XML files, Java classes, JavaServer Pages 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 (enterprise archive) files provide composite Java archives which 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.[5]

See also

References

  1. ^ "File Extension .JAR Details". Retrieved 29 November 2012.
  2. ^ "MIME : Java Glossary". Retrieved 29 November 2012.
  3. ^ Java Archive (JAR) Files
  4. ^ a b "PSARC/1997/123 - javaexec" (Mailing list). Open Solaris website.
  5. ^ Android Developer's Guide

External links