Java - Extract a JAR file on the command line

by
Jeremy Canfield |
Updated: March 23 2022
| Java articles
The JAR command is include in some, but not all installations of Java. On a Linux system, the which command can be used to determine if the JAR command is part of your $PATH. If something like this is returned, you may need to install Java on your Linux system.
~]# which jar
/usr/bin/which: no jar in (/sbin:/bin:/usr/sbin:/usr/bin)
Let's say you have a .jar file that contains the following.
com/
com/example
com/example/foo.class
The following command will extract the jar archive.
/path/to/bin/jar –xf /path/to/example.jar
This will create the following files and directories in your present working directory.
/com/example/foo.class
Did you find this article helpful?
If so, consider buying me a coffee over at