JAR file internals

A JAR file, short for Java Archive, is a file format used for packaging Java class files, associated metadata, and other resources into a single file for distribution. Although a JAR file is technically just a ZIP file, it contains specific elements shown in the following table that make it unique and essential for Java-based applications.

File Name Description
META-INF/MANIFEST.MF Contains metadata about the JAR file, including its version, author, and implementation details.
META-INF/LICENSE Specifies the terms and conditions under which the software can be used.
META-INF/NOTICE Provides copyright and licensing information for third-party libraries or code used in the application.
META-INF/DEPENDENCIES Lists the external dependencies required by the application.
META-INF/maven/ Contains metadata related to the project, such as its group ID, artifact ID, and version.
WEB-INF/ Contains resources related to a web application, such as HTML, CSS, and JSP files.
resources/ Contains non-Java resources used by the application, such as images, audio files, and configuration files.

Note that this is not an exhaustive list, and the file names and folder structures may vary depending on the specific application and its requirements.

MANIFEST.MF file

The META-INF/MANIFEST.MF file is a standard file that is included in every Java archive (JAR) file. It contains metadata about the JAR file, such as version information, author information, and dependencies.

The file has a simple structure, with each line consisting of a key-value pair separated by a colon. The keys are standardized and start with "Manifest-Version" and "Created-By", while the values are defined by the developer and can be used to provide information about the JAR file.

Here is an example of a META-INF/MANIFEST.MF file:

Manifest-Version: 1.0
                                        Created-By: 1.8.0_144 (Oracle Corporation)
                                        Main-Class: com.example.Main
                                        Class-Path: lib/library1.jar lib/library2.jar

In this example, the Manifest-Version key specifies the version of the manifest standard that is being used (in this case, version 1.0), and the Created-By key specifies the version of the Java development kit (JDK) that was used to create the JAR file.

The Main-Class key specifies the fully qualified name of the class that contains the main method for the application, while the Class-Path key specifies any external JAR files that are required by the application.

The META-INF/MANIFEST.MF file is used by the Java runtime environment (JRE) to launch applications and load required libraries. It can also be used by other tools, such as build tools and application servers, to manage dependencies and configuration settings.