Home > Articles > Programming > Java

  • Print
  • + Share This
Like this article? We recommend

Extracting Contents of a JAR File

As you probably guessed, extraction of the contents of a JAR file is not that hard either. The syntax below shows the basic command structure you would use:

jar xf jar-filename.jar [optional, space-delimited names of specific archived files]

In the syntax above, we use the JAR tool with the x option, indicating we want to perform an extraction. The f option indicates that we want our extraction to occur from the filename we specify (i.e., jar-filename.jar).

We can append the command with filenames of specific files that are housed in the archive which we want extracted. This is particularly useful if we are only interested in grabbing a subset of the files housed in our archive. By not specifying any specific file names, the tool goes ahead and extracts all the files in the archive.

When the extraction process occurs, the JAR tool automatically creates any directories that it sees were stored in the archive. It is also very important to take note: any existing files with the same name will be overwritten if there is a duplicate entry in the target extraction destination. The user is not prompted that an overwrite is occurring, so users should be prudent when using the tool.

  • + Share This
  • 🔖 Save To Your Account