jar-The Java Archiving Tool

In this article we are going to elaborate the JAVA commands (jar tool comes with java package). This article is the continuation of this previous article.

As we know the standard format of commands in java, the jar command also have the format(in command prompt).
jar [option] [jar/class name/file name] [parameters..]
And JAR is a standard ZIP or Archive format of java byte codes. The jar tool combines multiple files into a single JAR archive file. jar is a general-purpose archiving and compression tool, based on ZIP and the ZLIB compression format.

Jar Options :
-c : Creates new archive
-t : List table of contents for a archive
-x : Extracts named (or all) files from a archive
-u : Updates existing archive
-v : Generates verbose output on standard output
-f :  Specifies archive file name
-m : Include manifest information from specified manifest file
-e : Specify application entry point for stand-alone application bundled into an executable jar file
-0 : Stores only; [use no compression]
-M : Does not create a manifest file for the entries
-i : Generates index information for the specified jar files
-C : Changes to the specified directory and include the input file arguments. Its operation is similar to the -C option of the UNIX tar utility
-J[option] : Its supports options from java command. See my this post to get to know about those options.  Basically , it pass option into the Java runtime environment.

Note : A manifest file entry named META-INF/MANIFEST.MF is automatically generated by the jar tool and is always the first entry in the jar file. For more detail about jar file specified manifest , please see the specification here. Some commands with sample jar names :

Add a index to jar file : jar i [myJarFile] -J[option]

Create a jar file :
jar c[v0M]f [myJarFile] [-C dir] [myInputfiles] -J[option]
-Creates new jars(verbose output, store only and not creating manifest) specific file name, with change directory and a java option (including some files)

jar c[v0]mf [manifest] [myJarFile] [-C dir] [myInputfiles] -J[option] [-e entrypoint]
-Creates new jars(verbose output, store only),creating manifest, specific jar name, with change directory and a java option (including some files) and specify entry point(main class).

jar c[v0M] [-C dir] [myInputfiles] -J[option]
-Creates new jars(verbose output, store only and not creating manifest) with change directory and a java option(including some files)

jar c[v0]m [manifest] [-C dir] [myInputfiles] -J[option]
-Creates new jars(verbose output, store only),creating manifest with change directory and a java option (including some files)

Extract jar file :
jar x[v]f [myJarFile] [[myInputfiles]] -J[option]
jar x[v] [[myInputfiles]] -J[option]

Update jar file :
jar u[v0M]f [myJarFile] [-C dir] [myInputfiles] -J[option]
jar u[v0]mf manifest [myJarFile] [-C dir] [myInputfiles] -J[option] [-e entrypoint]
jar u[v0M] [-C dir] [myInputfiles] -J[option]
jar u[v0]m manifest [-C dir] [myInputfiles] -J[option]

List table of contents of jar file :
jar t[v]f [myJarFile] [[myInputfiles]] -J[option]
jar t[v] [[myInputfiles]] -J[option]

I have tried to explain creating Jar file part. Rest of them are followed by same kind of options. And the file those are used can be defined as.
myJarFile : The file which will be created
myInputfiles : Files added to jar. (separated by space whilewriting)
manifest : Pre-existing manifest file whose name : value pairs are to be included in MANIFEST.MF in the jar
entrypoint : The name of the class that set as the application entry point 

Please feel free to comment. As more jar creating option I use , I will add them incrementally. 

No comments:

Post a Comment