Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewing contents of a .jar file [closed]

Tags:

java

jar

viewer

People also ask

Can we read a JAR file?

To view individual files in a non-executable jar file, you can obtain compression/decompression software that works with jar files. We recommend using either 7-Zip or WinRAR. Once you have installed this software, run the software, open the jar file, and extract the files contained in it.

How do I unpack a JAR file in Windows?

To unpackage a JAR, you need a program that can extract compressed files. Windows includes functionality for this, but you can also use file extraction software like 7-Zip or WinRAR to get the job done. Open the JAR file within the software, and you can browse all the folders and files within it.


Using the JDK, jar -tf will list the files in the jar. javap will give you more details from a particular class file.


I usually open them with 7-Zip... It allows at least to see packages and classes and resources.
Should I need to see methods or fields, I would use Jad but of course, it is better to rely on (good) JavaDoc...

Now, somewhere on SO was mentioned some Eclipse plug-ins, to find in which jar file a class is located, perhaps they can do more (ie. what you requested).

[EDIT] Reference to SO thread. Not what is asked, but somehow related, thus useful: Java: How do I know which jar file to use given a class name?


What I use personally is JD-GUI. It is a free 'decompiler', as it allows you to see the source code, classes, and objects in the classes, as well as see the file structure in a tree menu to the left. However, it does not allow you to modify the classes directly.

JD-GUI's website: http://jd.benow.ca/


In case someone don't know this already, a JAR file is just a ZIP file that contains the program's classes, resources, etc., and some metadata. You can extract one to see how it's put together.

Hence I am using unzip command which is easy to remember and use.

unzip -l <jar-file-name>.jar

For example, if you have a jar file with name test.jar then unzip -l test.jar will list all the content of jar file.

While all other answers are great, but in most of them, you would have to use some software like 7 zip or JDK or some other eclipse tool while this doesn't require you to have any of these big s/w and it comes by default in linux and mac so its very lightweight and handy to use.

You can also use zipinfo <your jar file>. if your OS supports this.


Method names, fields, etc.

By adding a jar to a project in an IDE, you can usually see methods and field names, but not the detailed implementation. NetBeans can do it, Eclipse probably, IntelliJ probably, etc. You can browse the jar structure directly within the IDE.

Just the contents

For anything such as viewing the contents, you could use :

  • jar tvf jarfile.jar
  • winzip or any zip tool

The source code

To access source code, you would use a decompiler such as JAD or one of its frontends or another decompiler. If the code is obfuscated, then ...


jar -tvf file_name.jar

above will only print names of the files.

To view the content of files, you can extract the files in a folder by:

jar -xvf file_name.jar

this will unzip jar file & put the content in same directory where you are running this.

Or in Windows rename .jar file to .zip & then you can unzip to extract & view the content of jar file. As jar is internally a zip file.


Extending Tom Hawtin answer, you can pipe the listing to filter out desired class or files:

jar tf my-fat-jar-file.jar | grep filename

This should work on bash/zsh and similars, or emacs' eshell.

Additional information: https://docs.oracle.com/javase/tutorial/deployment/jar/view.html