SE450: Java Tools: jar [36/41] ![]() ![]() ![]() |
The jar tool is basically a command line zip tool. Java ARchives are just zip files, with special directories in them that Java uses to store information about the Java ARchive. For this class, jar is very useful for submitting your homework as one file.
Jar has very similar arguments to the unix tar command (Tape ARchive), so if you are familiar with it, you will have no problem picking up jar.
Jar basically has four commands, create (-c), list (-t), extract (-x), and update (-u). The -f command is used to specify the filename that you want to run the command on (to update, extract, list, etc) and the -v command will turn on verbose mode which will give you more detail of the command.
For example, to list the contents of the tools.jar file in $JAVA_HOME/lib, issue the command
jar tf tools.jar
and you will see a listing of every file in the archive. To extract all the files (you may not want to do this, there are a lot of them) run:
jar xf tools.jar
For example, to create a zip file for homework submission, first open a command prompt and go to the directory where the submission files exist. Then, run the command
jar cfM submission.zip *
and there will be a new file created called submission.zip with all the files in your directory. The M is to omit the manifest, a special file that stores information about the archive that java can use.