Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine which methods are used by a Java class

Tags:

java

import

class

I need to provide a report of which APIs are used by our code, and exactly which methods are called. For a Windows DLL, I would use "dumpbin /imports" - is there an equivalent for a Java .class file?

javap seems to be the obvious place to look, but I can't find any options that seem to do what I'm after.

like image 210
Paul Butcher Avatar asked Sep 12 '26 22:09

Paul Butcher


1 Answers

javap -c class1 class2 ... | grep invoke

You will get all the runtime calls. You should filter them from your APIs and you will get calls to imported methods.

You might also want to determine used imported fields:

javap -c class1 class2 ... | grep getstatic (search also putstatic, putfield, getfield)

like image 149
linuxbuild Avatar answered Sep 15 '26 10:09

linuxbuild



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!