tags:

views:

1398

answers:

15

What would be the easiest way to view classes, methods, properties, etc. inside a jar file? I'm looking for something equivalent to the very useful Lutz Roeder .NET Reflector - for Java

+7  A: 

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?

PhiLho
+5  A: 

Use WinRar. It will open the folder structure for you in intact manner. Also allows in-archive editing, while preserving paths.

Afterall, a JAR file is a ZIP archive only.

Mohit Nanda
+1  A: 

Well, a jar-file is just a zip-file, so if you unzip it (with your favorite unzipping utility), you get all the files inside.

If you want to look inside the class files to see the methods, you'll need a tool for that. As PhiLho mentions, Eclipse is able to do that (by default), and I would think most Java IDEs are capable of that.

Jeroen Heijmans
A: 

You could try JarSpy. There is an IDEA plugin version of it that I use.

Dan Dyer
A: 

If the jar file has been obfuscated you won't be able to see the source.

+5  A: 

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

Tom Hawtin - tackline
+1  A: 

I prefer JAR Browser, it has a simple interface where you can browse multiple JARs, and search for a specific class across multiple JARs simultaneously.

audiodude
+3  A: 

Jad is klunky and no longer maintained. I've switched to "Java Decompiler", which has a slick UI and support for new language features.

Every decompiler I've used, though, runs into code it doesn't successfully decompile. For those, it helps to understand the disassembled Java byte code produced by the standard JDK tool, javap.

erickson
+1  A: 

Eclipse 3.4 JDT

It is not the quickest way because you have to drag it into your eclipse first. But you will have full java class browsing, even with decompile enabled.

Dennis Cheung
A: 

You can open them with most decompression utilities these days, then just get something like DJ Java Decompiler if you want to view the source.

John T
A: 

Your IDE should also support this. My IDE (SlickeEdit) calls it a "tag library." Simply add a tag library for the jar file, and you should be able to browse the classes and methods in a hierarchical manner.

TREE
+1  A: 

If I understand correctly, you want to see not only classes but also methods, properties and so on. The only tool I know that can do it is Eclipse - if you add a jar to project classpath, you would be able to browse its classes with methods and properties using usual package explorer.

Anyway, this is a good idea for a good standalone Java tool

Yoni Roit
A: 

I've set the default action in windows to "Open with WinZip". This makes it easy to manage JARs as archives. You can even add/remove files manually.

Chris Nava
+1  A: 

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 ...

A: 

In Eclipse 3.4 do

  1. Drag the jar file in question into a Java project. A copy of the jar file appears.
  2. Right click on the jar file, and choose "Build Path" -> "Add to Build Path".
  3. Jar file is moved to "Referenced Libraries" node, where it can be opened and navigated in the Project Explorer pane.

If seeing source code too is an issue, open a new question.

For navigation on Jar-file level (as a zip file) I use 7zip which works very well, and allows seeing and editing entries which is great for trouble shooting.

Thorbjørn Ravn Andersen