JAR(1)
π¦ JAR(1) β JDK Commands π¦
okay bestie, welcome to the JAR(1) page from the JDK Commands β the manual for the jar command. Every flag is getting its moment, no cap. π
π NAME π
jar β create an archive for classes and resources, and manipulate or restore individual classes or resources from an archive. Archive maker, archive manipulator, archive restorer β she contains multitudes. π«Ά
β¨ SYNOPSIS β¨
jar [OPTION ...] [ [--release VERSION] [-C dir] files] ...
π¦ DESCRIPTION π¦
The jar command is a general-purpose archiving and compression tool, based on the ZIP and ZLIB compression formats. Initially, the jar command was designed to package Java applets (not supported since JDK 11) or applications; however, beginning with JDK 9, users can use the jar command to create modular JARs. For transportation and deployment, it's usually more convenient to package modules as modular JARs. Logistics queen behavior. β¨
The syntax for the jar command resembles the syntax for the tar command. It has several main operation modes, defined by one of the mandatory operation arguments. Other arguments are either options that modify the behavior of the operation or are required to perform the operation. Mandatory means mandatory, bestie β pick an operation. π
When modules or the components of an application (files, images and sounds) are combined into a single archive, they can be downloaded by a Java agent (such as a browser) in a single HTTP transaction, rather than requiring a new connection for each piece. This dramatically improves download times. The jar command also compresses files, which further improves download time. The jar command also enables individual entries in a file to be signed so that their origin can be authenticated. A JAR file can be used as a class path entry, whether or not it's compressed. One connection, so many files β it's giving efficiency. π¦
An archive becomes a modular JAR when you include a module descriptor, module-info.class, in the root of the given directories or in the root of the .jar archive. The following operations described in Operation Modifiers Valid Only in Create and Update Modes are valid only when creating or updating a modular jar or updating an existing non-modular jar:
--module-version--hash-modules--module-path
Note: All mandatory or optional arguments for long options are also mandatory or optional for any corresponding short options. Short option, long option β same rules, same energy.
π MAIN OPERATION MODES π
When using the jar command, you must specify the operation for it to perform. You specify the operation mode for the jar command by including the appropriate operation arguments described in this section. You can mix an operation argument with other one-letter options. Generally the operation argument is the first argument specified on the command line. Main character energy: operation first, chaos later. π
-cor--createβ Creates the archive. Fresh archive, who dis? β¨-iFILE or--generate-index=FILEβ Generates index information for the specified JAR file. This option is deprecated and may be removed in a future release. π¨-tor--listβ Lists the table of contents for the archive. Table of contents, but make it JAR. π-uor--updateβ Updates an existing JAR file. Glow-up, but for archives. π-xor--extractβ Extracts the named (or all) files from the archive. If a file with the same name appears more than once in the archive, each copy will be extracted, with later copies overwriting (replacing) earlier copies unless-kis specified. Last copy wins unless-ksays absolutely not. π«Ά-dor--describe-moduleβ Prints the module descriptor or automatic module name. Tell us about yourself, module. π--validateβ Validate the contents of the JAR file. See Integrity of a JAR File section below for more details. Vibe check, but official. β
πΈ OPERATION MODIFIERS VALID IN ANY MODE πΈ
You can use the following options to customize the actions of any operation mode included in the jar command. Any mode, any time β these are the versatile besties. π«Ά
-CDIR β When used with the create operation mode, changes the specified directory and includes the files specified at the end of the command line. The synopsis shape it's talking about is:
jar [OPTION ...] [ [--release VERSION] [-C dir] files]
When used with the extract operation mode, specifies the destination directory where the JAR file will be extracted. Unlike with the create operation mode, this option can be specified only once with the extract operation mode. Create mode: flexible. Extract mode: one -C only, bestie. π
-fFILE or--file=FILEβ Specifies the archive file name. Name your archive, icon. β¨--releaseVERSION β Creates a multirelease JAR file. Places all files specified after the option into a versioned directory of the JAR file namedMETA-INF/versions/VERSION/, whereVERSIONmust be must be a positive integer whose value is9or greater. At run time, where more than one version of a class exists in the JAR, the JDK will use the first one it finds, searching initially in the directory tree whoseVERSIONnumber matches the JDK's major version number. It will then look in directories with successively lowerVERSIONnumbers, and finally look in the root of the JAR. Version directories going newest to oldest to root β search order slay. π¦-vor--verboseβ Sends or prints verbose output to standard output. Tell me everything, honestly. π£οΈ
π OPERATION MODIFIERS VALID ONLY IN CREATE AND UPDATE MODES π
You can use the following options to customize the actions of the create and the update main operation modes. Create and update only β read the room. π
-eCLASSNAME or--main-class=CLASSNAMEβ Specifies the application entry point for standalone applications bundled into a modular or executable modular JAR file. Main class, main character. π-mFILE or--manifest=FILEβ Includes the manifest information from the given manifest file. Manifest info incoming. π-Mor--no-manifestβ Doesn't create a manifest file for the entries. No manifest, no problem. π--module-version=VERSIONβ Specifies the module version, when creating or updating a modular JAR file, or updating a non-modular JAR file. Put a version on it. π--hash-modules=PATTERNβ Computes and records the hashes of modules matched by the given pattern and that depend upon directly or indirectly on a modular JAR file being created or a non-modular JAR file being updated. Hashes, recorded and matched β very security-core. π₯-por--module-pathβ Specifies the location of module dependence for generating the hash. Where the module dependencies live. π@fileβ Reads jar options and file names from a text file as if they were supplied on the command line. Argument delivery via text file, iykyk. π
π§ OPERATION MODIFIERS VALID ONLY IN CREATE, UPDATE, AND GENERATE-INDEX MODES π§
You can use the following options to customize the actions of the create (-c or --create), the update (-u or --update), and the generate-index (-i or --generate-index=FILE) main operation modes. Three modes, one little club. π
-0or--no-compressβ Stores without using ZIP compression. No compression, just vibes. π«Ά--date=TIMESTAMPβ The timestamp in ISO-8601 extended offset date-time with optional time-zone format, to use for the timestamp of the entries, e.g."2022-02-12T12:30:00-05:00". Timestamp with time zone realness. β°
π OPERATION MODIFIERS VALID ONLY IN EXTRACT MODE π
--dirDIR β Directory into which the JAR file will be extracted. Destination directory, bestie. π-kor--keep-old-filesβ Do not overwrite existing files. If a Jar file entry with the same name exists in the target directory, the existing file will not be overwritten. As a result, if a file appears more than once in an archive, later copies will not overwrite earlier copies. Also note that some file system can be case insensitive. Protect the existing files β and remember case sensitivity is not universal. π‘οΈ
π OTHER OPTIONS π
The following options are recognized by the jar command and not used with operation modes. Side quest options, but make them useful. β¨
-hor--help[:compat]β Displays the command-line help for thejarcommand or optionally the compatibility help. Help, but make it optional-compat. π«Ά--help-extraβ Displays help on extra options. Extra help for extra options. π--versionβ Prints the program version. Version check, iconic. π
π₯ INTEGRITY OF A JAR FILE π₯
As a JAR file is based on ZIP format, it is possible to create a JAR file using tools other than the jar command. The --validate option may be used to perform the following integrity checks against a JAR file: Trust but verify, bestie. β
- That there are no duplicate Zip entry file names
- Verify that the Zip entry file name:
- is not an absolute path
- the file name is not
.or.. - does not contain a backslash,
'\' - does not contain a drive letter
- path element does not include
.or..
- The API exported by a multi-release jar archive is consistent across all different release versions.
The jar tool exits with a status of 0 if there were no integrity issues encountered and >0 if an error/warning occurred. Exit 0 is the clean vibe; >0 means something in the group chat went wrong. π
When an integrity issue is reported, it will often require that the JAR file is re-created by the original source of the JAR file. If it's cooked, go back to the original source and rebuild β no shortcuts. π
π EXAMPLES OF JAR COMMAND SYNTAX π
okay bestie, this is the part that actually makes it click π‘ β real commands, real vibes, no cap. every single one of these is copy-paste-able and honestly? iconic.
- Create an archive,
classes.jar, that contains two class files,Foo.classandBar.class.
jar --create --file classes.jar Foo.class Bar.class
literally the hello-world of jar-ing π«Ά two class files, one archive, done.
- Create an archive,
classes.jar, that contains two class files,Foo.classandBar.classsetting the last modified date and time to 2021 Jan 6 12:36:00.
jar --create --date="2021-01-06T14:36:00+02:00"
--file=classes.jar Foo.class Bar.class
the way that --date lets you time travel your timestamps π°οΈβ¨ (yes the timezone offset is in there, she's thorough)
- Create an archive,
classes.jar, by using an existing manifest,mymanifest, that contains all of the files in the directoryfoo/.
jar --create --file classes.jar --manifest mymanifest -C foo/
reusing a manifest you already have? efficient queen behavior π and -C foo/ scoops up everything in that directory.
- Create a modular JAR archive,
foo.jar, where the module descriptor is located inclasses/module-info.class.
jar --create --file foo.jar --main-class com.foo.Main
--module-version 1.0 -C foo/classes resources
modular jar build, main class and module version set, plus a resources directory tossed in for good measure π
- Update an existing non-modular JAR,
foo.jar, to a modular JAR file.
jar --update --file foo.jar --main-class com.foo.Main
--module-version 1.0 -C foo/module-info.class
glow-up in progress π your boring non-modular jar becomes a modular one, no starting over required.
π¦ the multi-release jar example (she's the main character, fr)
- Create a versioned or multi-release JAR,
foo.jar, that places the files in theclassesdirectory at the root of the JAR, and the files in theclasses-10directory in theMETA-INF/versions/10directory of the JAR.
so in this example, the classes/com/foo directory contains two classes: com.foo.Hello (the entry point class) and com.foo.NameProvider, both compiled for JDK 8. then the classes-10/com/foo directory contains a different version of the com.foo.NameProvider class β this one packing JDK 10 specific code, compiled for JDK 10. π two of the same class living different lives.
given this setup, create a multirelease JAR file foo.jar by running the following command from the directory containing the directories classes and classes-10:
jar --create --file foo.jar --main-class com.foo.Hello -C
classes . --release 10 -C classes-10 .
and now foo.jar contains:
% jar -tf foo.jar
META-INF/
META-INF/MANIFEST.MF
com/
com/foo/
com/foo/Hello.class
com/foo/NameProvider.class
META-INF/versions/10/com/
META-INF/versions/10/com/foo/
META-INF/versions/10/com/foo/NameProvider.class
as well as other information, the file META-INF/MANIFEST.MF will contain the following lines to indicate that this is a multirelease JAR file with an entry point of com.foo.Hello:
...
Main-Class: com.foo.Hello
Multi-Release: true
so assuming that the com.foo.Hello class calls a method on the com.foo.NameProvider class, running the program using JDK 10 will ensure that the com.foo.NameProvider class is the one in META-INF/versions/10/com/foo/. π₯ running the program using JDK 8 will ensure that the com.foo.NameProvider class is the one at the root of the JAR, in com/foo. the correct one just appears, iykyk β¨
- Create an archive,
my.jar, by reading options and lists of class files from the fileclasses.list.
Note: to shorten or simplify thejarcommand, you can provide an arg file that lists the files to include in the JAR file and pass it to thejarcommand with the at sign (@) as a prefix.
jar --create --file my.jar @classes.list
okay but the at-sign trick is SO underrated π«Ά but listen β if one or more entries in the arg file cannot be found then the jar command fails without creating the JAR file. like, no jar for you π all-or-nothing energy.
- Extract the JAR file
foo.jarto/tmp/bar/directory.
jar -xf foo.jar -C /tmp/bar/
alternatively, you can also do:
jar --extract --file foo.jar --dir /tmp/bar/
two ways to do the exact same thing, pick your vibe π short flags or long flags, both slay.
and that's the whole page, bestie!! πβ¨ you just read the entire JAR(1) manual and honestly you ate that. go forth and archive things with confidence π
this iconic little doc is from JDK 25.0.5.0.3, dated 2026 β that's the source/version and date right there, folded into a cute sign-off instead of a boring footer line π¦π
π¦ where this page comes from
- arch rolling: jdk25-openjdk 25.0.5.0.3.u1-1 Β· LicenseRef-Java
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms