JAR (file format)

A Java Archive ( colloquially called because of the file extension JAR ) file is a ZIP file that can contain additional metadata to a file " META-INF/MANIFEST.MF ". JARs are used primarily for distribution of Java class libraries and programs. The term can be understood as a pun on the English word jar, German " vessel ".

Use

Jar files were originally introduced so required by Java applets Java classes do not need to be recharged separately from the net. The transmission of multiple classes in a file is more efficient and, in addition, files can be compressed.

Through the "Manifest " file can be set as the Java - applications is started. Thus, even in graphical user interfaces, such as Windows, Mac OS X or KDE, start the application without using the command line (assuming the file extension. Jar the corresponding command has been assigned ). With java-jar you can start JAR files from the command line. JAR archives store file names internally UTF -8 encoded, so that they may also contain umlauts. Prerequisite for the execution of JARs and Java programs is always an installed Java Runtime Environment.

JAR files ( the syntax of tar used ), or, if the file names contain only ASCII characters, created with any zip program with the jar command from the JDK. In addition, in the two packages " java.util.jar " and " java.util.zip " provides the Java Platform, Standard Edition of classes to read JAR or ZIP archives or to create.

For example, the following command displays the contents of a JAR file named test.jar.

Jar tvf test.jar The letter t stands for " Show Contents " (from English table of contents ), v for verbose output (of English verbose) and f to denote that from a file ( english file) is to be read, whose name follows.

Manifesto

Each Java archives can provide different information about the contents of the archive in the folder " META -INF " with a file called " MANIFEST.MF ". Among the most important meta- information

  • Which included at runtime version detectable class libraries,
  • Information contained JavaBeans and
  • The name of the main class of a contained Java application.

This manifest file is a simple line-oriented text file that contains multiple pairs of names and values ​​, each of which defines a so-called attribute. An attribute is a property of the whole application, the class library contained or even a single Java package (package ) or a single class. In addition, it is divided into several sections ( sections ).

The first section is called main section (main section) and defines attributes that apply to the entire Java archives. It always begins with the definition of the attribute "Manifest - Version", while the other attributes are optional. The following sections relate to a single package or a class and are optional, as well as the attributes contained therein. Unknown attributes are ignored and do not cause error messages. If you define an attribute in both the main section and in a single section, as defined in the individual section of the value superimposed on the pre-assigned in the main section for that component ( package or class) to which the section applies.

Example

The following example shows a section of the Manifesto contained in the runtime environment of Java 1.4 file " rt.jar ".

Manifest - Version: 1.0 Specification -Title: Java Platform API Specification Created -By: 1.4.2_05 (Sun Microsystems Inc.) Implementation -Title: Java Runtime Environment Specification vendor Sun Microsystems, Inc. Specification - Version: 1.4 Implementation - Version: 1.4.2_05 Implementation -Vendor: Sun Microsystems, Inc. Name: javax / swing / JRadioButtonMenuItem.class Java - Bean: True Name: javax / swing / JList.class Java - Bean: True The main section in this example can be inferred that this manifesto is constructed as described in ( the only previous ) version 1 of the JAR file specification from Sun Microsystems. The other attributes of this main section provide information on the objective met by the library specification, the producer of the Java archive, the name of the implementation, as well as manufacturer and version of the specification used and the implementation contained. The following two sections of the example relate to a class that is marked as a JavaBean.

Derived formats

Other specializations of the JAR format, for example WAR files (Web Application Archive ), EAR files (Enterprise Application Archive ), or OpenDocument files.

Utilities

The Java Development Kit contains several programs for manipulating JAR files:

Programming tools not included in the JDK JAR files:

Pictures of JAR (file format)

18371
de