Viewing contents of a .jar file [closed]
Solution 1:
Using the JDK, jar -tf
will list the files in the jar. javap
will give you more details from a particular class file.
Solution 2:
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?
Solution 3:
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.
Solution 4:
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/
Solution 5:
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 ...