Lesson 4 | Working with JAR files |
Objective | Use the JAR utility to manipulate JAR files. |
jar
You must specify one of the following main operation options to define the action to be performed:
-c
(create a new archive)-t
(list the contents of an archive)-x
(extract files from an archive)-u
(update an existing archive)-d
(describe the module)-i
(generate the index information for JAR service provider configuration files)Example: jar -c ...
indicates you're creating a JAR file.
-f
option typically requires a filename to specify the JAR file being operated on.Example: jar -cf myarchive.jar ...
-f
(specify the archive file name)-e
(specify the entry point for standalone applications bundled in the JAR file)-v
(generate verbose output about the operation)-m
(include a custom manifest file when creating/updating an archive)-M
(do not automatically create a manifest file)-0
(store files without using ZIP compression)-P
(preserve file permissions in the archive)-i
(generate an index file for JAR services)jar -cf myarchive.jar -C build/classes .
-c
: Create an archive-f
: Specify the JAR file name-C
: Change to the specified directory and include all filesjar -tf myarchive.jar
-t
: List contents-f
: Specify the JAR file to listjar -xf myarchive.jar
-x
: Extract-f
: Specify the JAR filejar -cfm myarchive.jar manifest.txt -C build/classes .
-c
: Create-f
: Specify the JAR file-m
: Include a custom manifestOption | Description |
---|---|
f | Identify the name of the archive as the first file in the Files argument. |
c | Create a new archive. |
m | Create a manifest file for an archive based on an external manifest file. (The external manifest file is provided as the second file in the Files argument.) |
t | List the contents of an archive. |
x | Extract all the files in an archive, or just the files provided in the Files parameter. |
v | Output detailed information about the actions being performed. |
jar ft SomeArchive.jar
jar cvf BeansBook.jar BeansBook/util/GenericButtonAdapter.class
adding: BeansBook/util/GenericButtonAdapter.class in=2999 out=1507 deflated 49.0%
jar tvf BeansBook.jar
179 Sat Feb 15 16:27:04 EST 1997 META-INF/MANIFEST.MF 2999 Sat Feb 08 14:33:18 EST 1997 BeansBook/util/GenericButtonAdapter.class
jar xf BeansBook.jar META-INF
Manifest-Version: 1.0 Name: BeansBook/util/GenericButtonAdapter.class Digest-Algorithms: MD5 SHA MD5-Digest: wuX4KYNI+D3QYBTtNn6wdA== SHA-Digest: R8cIwi1GSAgAdwAdrxb9AXlSBV8=