Introduction
A .jar file packs a Java program or library into one file: its compiled
.class files, the resources they use and
a manifest. A JAR whose manifest names a main class can be run directly with
java -jar, and libraries are shared as JARs through repositories such as
Maven Central.
Several other formats are JARs with extra rules, such as web application archives
(.war) and enterprise archives (.ear).
Structure
A JAR is a ZIP archive. The class files sit in
folders that follow their package names, so the class
com.example.App is stored as com/example/App.class. The
META-INF/ folder holds the manifest, META-INF/MANIFEST.MF, a
text file of Name: value lines such as Main-Class and
Class-Path. A signed JAR adds a signature file and a signature block there
too, and a JAR that provides services lists them under
META-INF/services/.
The manifest’s syntax and every attribute are on the
manifest page; the signature files and how
they are checked on signed JAR files; and the
rest of META-INF/, multi-release JARs, modules and the old JAR index on
META-INF and layout.
Manifest-Version: 1.0
Main-Class: com.example.App
Class-Path: lib/library.jar
Created-By: 21 (Eclipse Adoptium)
Not described
Known, not yet covered
Links
Software
- OpenJDK – the Java platform, with
javato run JARs and thejartool to make and list them (Windows, macOS, Linux) - IntelliJ IDEA – JetBrains’ Java IDE, which builds JARs (Windows, macOS, Linux)
- Eclipse – Java IDE that exports projects as JARs (Windows, macOS, Linux)
- JD-GUI – shows the decompiled source of the classes in a JAR (Windows, macOS, Linux)
- 7-Zip – free archiver that opens the ZIP inside (Windows)
Developers
- java.util.jar – the standard library’s classes for reading and writing JARs (Java)
Reference
- JAR File Specification – Oracle’s specification, including the manifest format