Java - JAR
f: file specified in the command line, instead of stdin/stdout;
t: view the table of the contents;
e: specify the entrypoint
v: verbose output;
0(zero): without compressing;
M: without generating default Menifest file;
m: include an existing Menifest file;
-C: change current directory;
Note: (from oracle.com)
- The metadata in the JAR file, such as the entry names, comments, and contents of the manifest, must be encoded in UTF8.
- The manifest must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.
- When you create a JAR file, the time of creation is stored in the JAR file. Therefore, even if the contents of the JAR file do not change, when you create a JAR file multiple times, the resulting files are not exactly identical. You should be aware of this when you are using JAR files in a build environment. It is recommended that you use versioning information in the manifest file, rather than creation time, to control versions of a JAR file
Create a jar from input-files:
$ jar cf foo.jar <input-files>
Create a jar and add existing manifest to default:
$ jar cmf <existing-manifest> foo.jar <input-files>
bar subdirectory, and all files in that directory:
$ jar cf foo.jar -C bar .
View the table of the contents
$ jar tf foo.jar
$ jar tvf foo.jar
$ jar xf foo.jar $ jar xf foo.jar <archived-files>
Update files in jar
$ jar uf foo.jar <input-files>
Update files in images folder(change to images before update)::
$ jar uf foo.jar -C images <input-files>
$ java -jar foo.jar
There should be only one manifest file, and the path/name is fixed:
header: value pairs.
The manifest version is set in default file when generated
Set the entry point for the jar, specify a class with
public static void main(String args)
Save it in Manifest.txt and run:
$ jar cfm foo.jar Manifest.txt <input-files>
e to specify the entrypoint during creation::
$ jar cfe foo.jar <classname> <input-files>
Class-Path: foo.jar bar.jar baz.jar
The versioning headers should appear directly beneath the Name header for the package:
Name: java/util/ Specification-Title: Java Utility Classes Specification-Version: 1.2 Specification-Vendor: Example Tech, Inc. Implementation-Title: java.util Implementation-Version: build57 Implementation-Vendor: Example Tech, Inc.
Note that the package name must end with a "/".
Definition: all classes defined in that package must be archived in the same JAR file. A sealed JAR specifies that all packages defined by that JAR are sealed unless overridden on a per-package basis.