JAR (file format): Difference between revisions
MoreThings (talk | contribs) m →Related formats: fix link |
→Related formats: Minor rewording |
||
Line 49: | Line 49: | ||
*[[EAR (file format)|'''EAR''']] ('''E'''nterprise '''AR'''chive) 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. |
*[[EAR (file format)|'''EAR''']] ('''E'''nterprise '''AR'''chive) 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. |
||
*[[Service Archive|'''SAR''']] ('''S'''ervice '''AR'''chive) is similar to EAR. It provides a <tt>service.xml</tt> file and accompanying JAR files. |
*[[Service Archive|'''SAR''']] ('''S'''ervice '''AR'''chive) is similar to EAR. It provides a <tt>service.xml</tt> file and accompanying JAR files. |
||
*[[APK_(file_format)|'''APK''']] ('''A'''ndroid Application '''P'''ac'''k'''age |
*[[APK_(file_format)|'''APK''']] ('''A'''ndroid Application '''P'''ac'''k'''age), a variant of the Java archive format, is used for [[Android_(operating_system)|Android]] applications.<ref>[http://developer.android.com/guide/appendix/glossary.html Android Developer's Guide]</ref> |
||
==See also== |
==See also== |
Revision as of 20:30, 29 November 2010
Filename extension |
.jar |
---|---|
Internet media type |
application/java-archive |
Uniform Type Identifier (UTI) | com.sun.java-archive |
Developed by | Netscape, Sun Microsystems [1] |
Type of format | file archive, data compression |
Extended from | ZIP |
In computing software, a JAR file (or Java ARchive) aggregates many files into one.[1] Software developers generally use .jar
files to distribute Java applications or libraries, in the form of classes and associated metadata and resources (text, images, etc.). JAR files build on the ZIP file format. 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, caution should be exercised as to the order of entries in the zip file headers as the manifest likely needs to be first.
Overview
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. 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 as
Main-Class: myPrograms.MyClass
Users can typically start such JAR files with a command similar to:
java -jar foo.jar
To unzip a jar file we can use any of the unzip software like WinZip etc. Otherwise we can use the below command to unzip:
jar -xf foo.jar
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 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.
Microsoft Windows users who prefer having Windows EXE files can use tools such as JSmooth, Launch4J, WinRun4J or NSIS - Java Launcher with automatic JRE installation 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).
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.[2]
See also
References
http://download.oracle.com/javase/tutorial/deployment/jar/
External links
- Oracle
- Original JAR File Specification
- Jar Class Loader (dynamically loading classes directly from Jar files)
- fastjar - alternative .jar creation program written in C