Understanding JAR File Format, Manifest Specification, Signing, Indexing, and Service Provider Mechanism
This article provides a comprehensive overview of the JAR file format, detailing the structure and purpose of the META-INF directory, manifest sections, signing files, index files, class‑path attributes, and service provider configuration, while also presenting the formal syntax specifications and examples for each component.
JAR files are ZIP‑based archives that bundle Java classes and resources; they may contain an optional META‑INF directory with configuration files such as MANIFEST.MF, INDEX.LIST, and signature files.
The manifest is composed of a main section and per‑entry sections, each following a strict "name: value" syntax defined by a BNF‑style grammar. Main attributes include Manifest-Version, Created-By, Signature-Version, Class-Path, and various implementation and specification attributes; per‑entry attributes can define sealing, content type, digests, and custom properties like Magic.
Signing a JAR involves creating .SF and .DSA/.RSA files (or other digital‑signature extensions) that list digests of the manifest and each entry; verification checks these digests against the manifest and ensures no file has been altered after signing.
The INDEX.LIST file, generated with jar -i , maps package or file names to the JARs that contain them, enabling class loaders to locate resources efficiently instead of performing linear searches.
Service provider configuration files reside in META‑INF/services; each file is named after an abstract service class and lists concrete implementation class names, allowing the Java ServiceLoader mechanism to discover providers at runtime.
Additional rules cover line length limits, character encoding (UTF‑8), handling of unknown attributes, and backward‑compatible loading behavior when an INDEX.LIST is present.
360 Quality & Efficiency
360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.