4

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 Answers 2

4

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

0
2

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.

3
  • This is /not/ the way to identify method signatures from a jar file. See Caspar's response. Oct 4, 2010 at 7:23
  • @Hernal, depends on what you need. Oct 4, 2010 at 8:17
  • 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. Oct 4, 2010 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.