The basic format of the command for creating a JAR file is:The options and arguments used in this command:jar cf jar-file input-file(s)
- The c option indicates that you want to create a JAR file.
- The f option indicates that you want the output to go to a file rather than to stdout. Always use this option.
- jar-file is the name that you want the resulting JAR file to have.
- You can use any filename for a JAR file.
- By convention, JAR filenames are given a .jar extension.
- The input-file(s) argument is a space-separated list of 1 or more files that you want to be placed in your JAR file.
- The input-file(s) argument can contain the wildcard * symbol.
- If any of the "input-files" are directories, the contents of those directories are added to the JAR archive recursively.
- The options can appear in either order, but there must not be any space between them.
- The command above generates a:
- compressed JAR file and place it in the current directory
- default manifest file for the JAR archive.
Additional options to the cf options of the basic command:
Option Description v Produces verbose output on stdout while the JAR file is being built.
The verbose output tells the name of each file as it's added to the JAR file.0 (zero) Indicates that you don't want the JAR file to be compressed. M Indicates that the default manifest file should not be produced. m Used to include manifest information from an existing manifest file. The format for using this option is: See Modifying a Manifest for more information about his option.jar cmf existing-manifest jar-file input-file(s)
The audio and images subdirectories contain sound files and GIF images used by the applet. To package this demo into a single JAR file named TicTacToe.jar, run this command from inside the TicTacToe directory:
jar cvf TicTacToe.jar TicTacToe.class audio images
adding: TicTacToe.class (in=3825) (out=2222) (deflated 41%)
adding: audio/ (in=0) (out=0) (stored 0%)
adding: audio/beep.au (in=4032) (out=3572) (deflated 11%)
adding: audio/ding.au (in=2566) (out=2055) (deflated 19%)
adding: audio/return.au (in=6558) (out=4401) (deflated 32%)
adding: audio/yahoo1.au (in=7834) (out=6985) (deflated 10%)
adding: audio/yahoo2.au (in=7463) (out=4607) (deflated 38%)
adding: images/ (in=0) (out=0) (stored 0%)
adding: images/cross.gif (in=157) (out=160) (deflated -1%)
adding: images/not.gif (in=158) (out=161) (deflated -1%)
jar cvf0 TicTacToe.jar TicTacToe.class audio images
jar cvf TicTacToe.jar *
The resulting JAR file would have this table of contents:jar cf ImageAudio.jar images audioMETA-INF/MANIFEST.MF
images/cross.gif
images/not.gif
audio/beep.au
audio/ding.au
audio/return.au
audio/yahoo1.au
audio/yahoo2.au