This article analyzes the usage of Jar packaging in more detail. Share it with everyone for your reference. The specific analysis is as follows:
jar is a standard java packaging command, located under the JAVA_HOME/bin/ directory. The main function is to package multiple files into a single jar file.
Create a jar file and copy the code as follows: jar c[v0Mmfe] [manifest] [jarfile] [entrypoint] [-C dir] inputfiles [-Joption]
Update the jar file copy code code as follows: jar u[v0Mmfe] [manifest] [jarfile] [entrypoint] [-C dir] inputfiles [-Joption]
Unzip the jar file and copy the code as follows: jar x[vf] [jarfile] [inputfiles] [-Joption]
Display the Jar package structure and copy the code as follows: jar t[vf] [jarfile] [inputfiles] [-Joption]
Add an index to the jar file and copy the code as follows: jar i jarfile [-Joption]
where [] represents optional
Parameter analysis is as follows:
jarfile: the target jar file to be created, updated, decompressed or displayed, used with the -f option
inputfiles: files or directories. Multiple files or directories are separated by spaces, indicating files or directories that need to be packaged, files or directories in the jar package to be decompressed, and files or directories in the jar package to be displayed. If it is a directory, it will be processed recursively. Multiple files are compressed in zip mode unless option 0 is added
Manifest: Specify the manifest file, used with the -m parameter
entrypoint: Specify the class name as the entry point of the application, used with the -e option. In particular, the order of manifest, jarfile, and entrypoint corresponding to the -m, -f, and -e parameters must be the same.
-C dir: When processing inputfiles, specify the directory of the subsequent inputfile. There can be multiple -C dir inputfiles.
-Joption: Specify the parameters of Java runtiome environment. There must be no space between -J and option.
Options:
c Create a new jar package
u Update existing jar packages
x Decompress the specified jar package
t displays jar package contents
f used with jarfile
v Output details
0 Do not use zip compression
M does not create a manifest file when generating a jar package
m used with manifest
e is used together with entrypoint to specify the entry class of the program and write it to the generated manifest file, corresponding to Main-Class. If used together with manifest and Main-Class is named in the manifest, packaging errors will occur.
I hope this article will be helpful to everyone’s Java programming.