LinuxCommandLibrary

jar

java Archive tool

TLDR

Create JAR file

$ jar cf [output.jar] [files...]
copy
Create with manifest
$ jar cfm [output.jar] [MANIFEST.MF] [files...]
copy
Extract JAR file
$ jar xf [archive.jar]
copy
List contents
$ jar tf [archive.jar]
copy
Create executable JAR
$ jar cfe [output.jar] [MainClass] [files...]
copy
Update JAR file
$ jar uf [archive.jar] [newfiles...]
copy
Extract specific file
$ jar xf [archive.jar] [path/to/file]
copy

SYNOPSIS

jar [options] [manifest] destination input-files

DESCRIPTION

jar is the Java Archive tool. It packages Java class files, resources, and metadata into a single JAR file for distribution and deployment.
JAR files use ZIP format with a manifest (META-INF/MANIFEST.MF) containing metadata. Executable JARs specify a main class in the manifest.

PARAMETERS

c

Create new archive.
x
Extract archive.
t
List table of contents.
u
Update existing archive.
f file
Specify archive filename.
m manifest
Include manifest file.
e class
Set entry point (main class).
v
Verbose output.
0
Store only (no compression).
C dir
Change to directory.

MANIFEST EXAMPLE

$ Manifest-Version: 1.0
Main-Class: com.example.Main
Class-Path: lib/dependency.jar
copy

CAVEATS

Order of flags matters. Manifest file needs newline at end. Paths are relative to current directory. Use -C for changing base directory.

HISTORY

The jar tool has been part of the JDK since Java 1.1 (1997). It's essential for Java deployment, evolving to support modules in Java 9+ and multi-release JARs.

SEE ALSO

java(1), javac(1), zip(1), unzip(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard