How to extract the contents of a jar file with command line?



Syntax:

The basic command to use for extracting the contents of a JAR file is:

jar xf jar-file [archived-file(s)]

Let’s look at the options and arguments in this command:

  • The x option indicates that you want to extract files from the JAR archive.
  • The f options indicate that the JAR file from which files are to be extracted is specified on the command line, rather than through stdin.
  • The jar-file argument is the filename (or path and filename) of the JAR file from which to extract files.
  • archived-file(s) is an optional argument consisting of a space-separated list of the files to be extracted from the archive. If this argument is not present, the Jar tool will extract all the files in the archive.

Examples:

To extract the files from a jar file,use,x, as in:

$ jar xf myFile.jar

To extract only certain files from a jar file, supply their filenames:

$ jar xf myFile.jar foo bar

Note that a jar file is a Zip file, and any Zip tool (such as 7-Zip) can look inside the jar. Useful for systems that don’t have a jar command Ex  CentOS

unzip file.jar -d dir_name_where_extracting