- Some Background
- Creating JAR Files
- Viewing Contents of Your JAR File
- Extracting Contents of a JAR File
- Updating Your JAR Files
- Sealing Packages in JARs
- JAR Indexing
Viewing Contents of Your JAR File
You can use the JAR tool to look inside a JAR file and view its contents. Doing this is simple. One example might be:
jar tf jar-filename.jar
In the syntax above, the t option states that we want to view the table of contents of jar-filename.jar. The f option indicates that we will provide the name of the archive we want to look into via the command line. (If we did not use this option, the tool would expect us to provide an argument via standard in.)
As we did during the creation of our JAR, we can also use the v option here to get a verbose output of its contents.
Below is the output of a typical view content operation:
jar tfv jar-filename.jar 0 Fri Mar 12 18:08:20 EST 2004 META-INF/ 71 Fri Mar 12 18:08:20 EST 2004 META-INF/MANIFEST.MF 1436 Fri Mar 12 18:07:56 EST 2004 jar-file.name.jar 14 Fri Mar 12 17:45:54 EST 2004 file2.txt 14 Fri Mar 12 17:47:32 EST 2004 file5.txt 0 Fri Mar 12 17:46:26 EST 2004 subdir3/ 14 Fri Mar 12 17:46:16 EST 2004 subdir3/file3.txt 14 Fri Mar 12 17:46:26 EST 2004 subdir3/file4.txt
Let's pay attention to a couple of things. The paths stored in our JAR file are relative, and pathnames are shown using forward slashes (UNIX style) even though I was using Microsoft Windows 2000. In JAR files, regardless of the operating system you are on, all pathnames are displayed with forward slashes. Also note the presence of a file named MANIFEST.MF in a directory called META-INF. We will talk about the significance of this file in just a bit.