views:

86

answers:

2

In Eclipse or NetBeans, when you "control + click" into a function, you can at least see its entire signature, even if it's in a jar file.

I am wonderging if it's possible to write a tool to pull out all the function signatures from a jar file. Is there any API for this?

I know jDepend seems to offer functions for this. However, I believe that there are some more generic ways to do this.

+2  A: 

I think the javap tool is what you are after.

Something like javap -classpath ./lib/ MyClass should do the trick.

See also this tutorial and the reference information for javap (google javap, I don't have enough reputation to post more than 1 link).

Caspar
This is awesome. I didn't know that. Thanks! (+1)
seanizer
+2  A: 

Jars are zip files so you can use the zip routines to get the byte code defintion for each class in the jar file.

Then, given the byte code, you can use a byte code analysis tool like javassist to load the byte code into a ClassFile, and then get the MethodInfo's which you can then process as you like.

Thorbjørn Ravn Andersen
This is /not/ the way to identify method signatures from a jar file. See Caspar's response.
Hemal Pandya
Well it's the way I would have done it. +1 for that :-)
seanizer
@Hernal, depends on what you need.
Thorbjørn Ravn Andersen
@Thorbjørn Ravn Andersen, Thank you for your help. javassist works okay for me. However, I have a question I would like to add here: do you know how I can get the retrn type name from "MethodInfo"? I used "getDescriptor()" but the returned String looks like this:(Ljava/io/File;)V It's close but still not the "java.io.File" I wished to have.
Winston Chen