List Files in a Jar File
By Pete Freitag
Have you ever wanted a list of the files inside a jar file? It's pretty simple to do using the jar
command that ships with java:
jar -tf somefile.jar
That's a great way to get a list of the class names and package names contained within a jar file.
You could also use this technique to list the contents of a zip file, since jar files are actually zip files. For example:
jar -tf some.zip
jar -tf Explained
In the example above we are passing the flag -tf
to the jar command. The t
in that jar
command indicates that we want a table listing of the contents of the jar file. The f
flag indicates that we will be passing the file name as the next argument.
You may find that the dash is not even necessary anymore, you can also try listing the file names in jar file like this:
jar tf file.jar
This is a handy one to commit to memory as a Java Developer.
List Files in a Jar File was first published on November 19, 2008.