jar cf my.jar foo.class bar.class - Creatingjar tf my.jar - View contentsjar xf my.jar - Extract contentsjava -jar my.jar - Run appjar cf jar-file input-file(s)
jar cf MyJar.jar MyClass.class1 MyClass2.classOther options include
v - Tells the name of each file it's added to the JAR-file
0 - Store only, does not use ZIP compressioin
M - Does not create default manifest file
m - Includes given manifest file
Application.class - Starts the appMyWindow.class - App's WindowMyWindow$1.class - Event Handling (Inner Class)bird.png - Bird's picturebirdpeck.png - Bird pecking picturejar cvf BirdApp.jar *.class *.png added manifest adding: Application.class(in = 428) (out= 321)(deflated 25%) adding: MyWindow$1.class(in = 556) (out= 377)(deflated 32%) adding: MyWindow.class(in = 1289) (out= 774)(deflated 39%) adding: bird.png(in = 8059) (out= 7976)(deflated 1%) adding: birdpeck.png(in = 8552) (out= 8472)(deflated 0%)
Above command created a compressed file, that contains following files and directory hierarchy
META-INF/MANIFEST.MF Application.class MyWindow.class MyWindow$1.class bird.png birdpeck.png
jar tf jar-filejar tf BirdApp.jar META-INF/ META-INF/MANIFEST.MF Application.class MyWindow$1.class MyWindow.class bird.png birdpeck.png
jar xf jar-filejava -jar jar-fileMETA-INF/MANIFEST.MF path of your JAR packageManifest-Version: 1.0 Created-By: 1.5.0_01 (Sun Microsystems Inc.)
header: value pairs.jar cfm jar-file manifestfile input-file(s)Main-Class: Application
jar cfm BirdApp.jar manifest.txt *.class *.pngManifest-Version: 1.0 Created-By: 1.5.0_01 (Sun Microsystems Inc.) Main-Class: Application
java -jar BirdApp.jar