| by Arround The Web | No comments

How to Extract JAR Files in Linux

The JAR, also known as the Java Archive, is a compressed file. The file can contain images and relevant class files to reduce the download time. JAR file also archives all the contents related to a file in a single destination.

You can extract the file using the regular platforms like WinRAR or WinZip. Hence, extracting the JAR file is more user-friendly and is easily accessible to people without a high programming knowledge. However, if you are still confused about extracting the JAR files in Linux, this guide will help you extract the JAR files easily in any Linux distro.

How to Extract JAR Files in Linux?

To thoroughly inspect and extract the contents of a JAR file in Linux, execute the following command:

$ jar -xvf <filename>.jar

For example, we want to extract the “sample.jar” file in the Downloads directory. We can execute the following commands one by one:

$ cd ~/Downloads

$ jar -xvf sample.jar

In the previous command, the xvf option represents the following:

  • X option instructs the system about extracting the files from the JAR archive.
  • V option generates the verbose output of the executed command.
  • F option represents the JAR file, in which the system will extract through the command.

If you get the following error, it is essential to install the JDK package in your system. Do it before extracting the file.

In case you don’t want to open the directory in the terminal before extracting the JAR file, run the following command:

$ jar -xvf /home/<username>/<directory>/<filename>.jar

You can also extract the JAR files in Linux without using the JAR command. The alternative way to extract these files is by using the “unzip” command to extract the file’s contents. There are no major differences in the usage of these two commands except that the JAR command works specifically only for the JAR files. While you can use the unzip command on similar archived and compressed files. Here is the basic command that you can use for extracting the JAR file:

$ unzip <filename>.jar

You can open and access the JAR file from the terminal using the following command:

$ java - jar <filename>.jar

The components of the JAR file can also be listed by either using the JAR command or using the unzip command. Here are the commands that you can use to list the content:

$ jar -xvf <filename>.jar

Or

$ unzip -tvf <filename>.jar

In the previous command, the “t” option is used for listing the contents available in the JAR file.

Conclusion

The JAR command works specifically only for the files with the “.jar” extension, while the unzip command works for all kinds of zipped files. JAR files were designed as a convenient storage folder for all the related file components and have aided in archiving the important class files related to the functioning of the main file.

We hope this article aids you in comprehending how to extract the JAR files, how to list their components, and how to open the JAR files in Linux by using the different commands. Follow the given steps to extract and list the contents of the JAR files in Linux with no hassle.

Share Button

Source: linuxhint.com

Leave a Reply