As a prior knowledge to understand the options in the JAR file First, I will explain the specifications of the JAR file.
The JAR file can contain the following elements: For each element, let's assume you have a JAR file called "sample-root.jar".
An overview of each is given below.
INDEX.LIST The file generated by the -i option of the jar command. In the JAR file that contains this file and the other JAR files that it depends on By indexing the location information of the stored package, It is used to speed up the processing of the class loader.
INDEX.LIST sample
JarIndex-Version: 1.0
sample-root.jar
com
com/example
com/example/app
If there are dependent JAR files, that information also follows...
MANIFEST.MF
The manifest file is a file that holds various meta information of the JAR file. It consists of a main section and individual sections, and can be set using the "attribute: value" pair method. If the same attribute is set more than once, the one in the individual section takes precedence.
#==========Main section==========
#version information(Mandatory)
Manifest-Version: 1.0
#Main attribute
#attribute:value
#Make sure there is one line between the main section and the individual sections
# ===========Individual section===========
#Attribute by entry
#attribute:value
Below are the main attributes that can be set in the manifest file.
[Main attribute]
--Manifest-Version:
Besides,
--Attributes defined for standalone applications (such as the Main-Class header) --Attributes defined for applets --Attributes defined to identify extensions --Attributes defined for extension and package versioning and sealing information
There are various attributes such as.
[Attributes by entry]
--Content-Type: Specifies the MIME type and subtype of a particular file in a JAR file. The value must be a string of the form "type / subtype".
sample-root.DSA and sample-root.SF are signature files, This article does not mention Java security tools, so I will omit them.
There is a function called a service provider to use the function of the external JAR file, A directory that stores concrete classes that interface with external JAR files. I will omit the explanation this time, so if you want to know more, please refer to the following article. Reference article: JAR file-Service provider function
--c: Newly created --u: Update --x: Extract files and directories --t: List of archive contents --f: Specify JAR file
--M: Do not create manifest file --For c or u: Do not create manifest file --u and if the manifest file exists: Delete the manifest file --m: Add the attribute pair of the specified manifest file --If an attribute with the same name exists: Overwrites with the specified manifest file attribute pair --If the attribute with the same name does not exist: Add the attribute pair of the specified manifest file.
--v: Display detailed information such as the operation performed by the jar command and the list of stored files.
--0: Generate JAR file without ZIP compression
--i
#Create a JAR file named jarfile with the resources under inputfiles
jar c[v0M]f jarfile [-C dir] inputfiles [-Joption]
#Create a jarfile with the resources under inputfiles
#Add value to manifest(Do not delete)
jar c[v0]mf manifest jarfile [-C dir] inputfiles [-Joption]
[About the description order of m option and f option] The order of description of m option and f option is not decided, For cmf, manifest jarfile, for cfm, jarfile manifest, and so on. It is necessary to match the order of the subsequent arguments.
#In the resources under inputfiles, reflect only the changed part in the jarfile and update
jar u[v0M]f jarfile [-C dir] inputfiles [-Joption]
#Only the parts that have changed in the resources under inputfiles are reflected in the jarfile.
#Update manifest(Add or remove values)
jar u[v0]mf manifest jarfile [-C dir] inputfiles [-Joption]
#Extract all directories and files in the jar file(Defrost)To do
#If inputfiles is specified, the specified target and below will be extracted.
jar x[v]f jarfile [inputfiles] [-Joption]
#List all directories and files in the jar file
#If inputfiles is specified, the list below the specified target is displayed.
jar t[v]f jarfile [inputfiles] [-Joption]
#INDEX in the specified jarfile.Create a LIST
jar i jarfile [-Joption]
Below is the first folder structure.
Specify the JAR file (f), output detailed information (v), Create a new JAR file called java-sample.jar (c).
#The current directory is/java-sample
$ jar cvf java-sample.jar .
Manifest added
.DS_Store is being added(Enter=6148)(Out=411)(93%Shrinked)
lib/Is being added(Enter=0)(Out=0)(0%Stored)
lib/commons-lang3-3.10.Adding jar(Enter=523372)(Out=481881)(7%Shrinked)
src/Is being added(Enter=0)(Out=0)(0%Stored)
src/com/Is being added(Enter=0)(Out=0)(0%Stored)
src/com/example/Is being added(Enter=0)(Out=0)(0%Stored)
src/com/example/app/Is being added(Enter=0)(Out=0)(0%Stored)
src/com/example/app/UseCommons.Java is being added(Enter=647)(Out=286)(55%Shrinked)
src/com/example/app/StrFactory.class is being added(Enter=308)(Out=234)(24%Shrinked)
src/com/example/app/UseCommons$CommonsHelper.class is being added(Enter=592)(Out=398)(32%Shrinked)
src/com/example/app/StrFactory.Java is being added(Enter=115)(Out=101)(12%Shrinked)
src/com/example/app/UseCommons.class is being added(Enter=732)(Out=441)(39%Shrinked)
Java-sample.jar is created in the current directory.
#The current directory is/java-sample
$ jar tf java-sample.jar
META-INF/
META-INF/MANIFEST.MF
.DS_Store
lib/
lib/commons-lang3-3.10.jar
src/
src/com/
src/com/example/
src/com/example/app/
src/com/example/app/UseCommons.java
src/com/example/app/StrFactory.class
src/com/example/app/UseCommons$CommonsHelper.class
src/com/example/app/StrFactory.java
src/com/example/app/UseCommons.class
If you execute it directly under java-sample, existing files and decompressed files will be mixed, so Create a folder called unzip and unzip it there.
#The current directory is/unzip
$ jar xf ../java-sample/java-sample.jar
The decompression result of the JAR file is expanded directly under unzip.
Recommended Posts