Java: Working with Jar File
A jar file (aka Java Archive) is a zip compressed bundle of compiled java class files.
jar tool to create or unpack jar files.
View Jar File
# list contents of the file x.jar jar tf x.jar
How to view content of java jar's manifest file?
# list MANIFEST content of a jar file unzip -p myfile.jar META-INF/MANIFEST.MF
The file “META-INF/MANIFEST.MF” is basically a index of the archive.
Example of a jar manifest file content:
Manifest-Version: 1.0 Archiver-Version: Plexus Archiver Created-By: Apache Maven Built-By: hudson Build-Jdk: 1.6.0_20 Main-Class: clojure.main
Creating Jar File
Here's a example of creating a jar file:
# create a java jar file # name it aa.jar # specify the program entrypoint is class Bb # contains all files of the pattern *.class and cc*/*.class jar cvfe aa.jar Bb *.class cc*/*.class
coption means create
voption means verbose (show lots info)
foption means from file (as opposed to from standard input “stdin”)
eoption specifies a entry point class. (when
javaruns on the jar file, this class will run.)
Extract Jar File
# extract jar file jar xvf x.jar