.JAR
Java archive
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).
Software
- OpenJDK, with
javato run them and thejartool to make and list them (Windows, macOS, Linux) - IntelliJ IDEA (Windows, macOS, Linux)
- Eclipse (Windows, macOS, Linux)
- JD-GUI (Windows, macOS, Linux)
- 7-Zip (Windows)
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/.
Manifest-Version: 1.0
Main-Class: com.example.App
Class-Path: lib/library.jar
Created-By: 21 (Eclipse Adoptium)