There are two main ways you can discover what a JAR file contains. These methods are platform-independent, so you can use them on Linux, Windows, or macOS.
Why Might You Need to Explore a JAR File?
A situation may occur when you want to verify the contents of a JAR file. You might want to update it or transfer the file across the web once you’ve verified what you’re sending.
The jar tool provides you with two ways to explore your JAR archive. The first method involves viewing the contents without extracting them. The second method is to extract the contents of the JAR file onto a filesystem.
Viewing Contents of a JAR File
In its simplest form, you can use jar to open a JAR file like this:
The t option tells the jar tool to output a table of contents. The f option tells jar to open a file rather than read an archive from stdin.
The order in which you indicate these options doesn’t matter. However, you need to ensure that there’s no space between them.
The example shown above assumes that your JAR file is in the current working directory. If it isn’t, then you can indicate the file path instead of just the file name.
To view more details about a JAR file, such as the date of creation, you can use the verbose option, v.
Extracting a JAR File
You can extract the contents of a JAR file using a command like this:
The x option directs the jar tool to extract the archive’s contents. This command will copy the contents of the JAR file into the current directory. It will match the directory structure of the items in the JAR file.
You may want to extract particular items from your JAR file rather than the entire contents. In such a case, you can indicate these items after the JAR filename:
This command will extract two HTML files from the JAR file, if they exist inside it.
Using a Graphical Approach
Sometimes you may prefer to use a graphical tool instead of the command line. In this case, you can opt for a GUI-based tool to open your JAR file. There are several such programs that you can use on Windows 10.