4

I am trying to print all the public methods of classes of a package in a jar file, as of now I only have been able to print class names using:

jar -tf my.jar

But now I want to print all the methods of all classes of a package in a jar file how can i do this using command prompt.

I have seen javap command but its not working. I couldn't find an example of what I want.

3 Answers 3

7

jar tf will list the contents for you.

javap will allow you to see more details of the classes (see the tools guide here).

For instance if you have a class named mypkg.HelloWorld in a jar myjar.jar then run it like

javap -classpath myjar.jar mypkg.HelloWorld
Sign up to request clarification or add additional context in comments.

2 Comments

is there no command like javap -classpath myjar.jar mypkg.* here * means all classes ..
try reflection then
4
#!/bin/sh
jar tf your.jar | grep '.class$' | tr / . | sed 's/\.class$//' | xargs javap -public -cp your.jar

What this does is: It lists the content of your.jar, filters out everything that doesn't end in .class, replaces all slashes with periods, and strips off the .class suffix. This gives us all the classes in your.jar in a form that can be passed to javap, which we do.

With the classpath set to your.jar, javap disassembles each class that we pass it (which is all of them), and prints eventhing that is publicly accessible in them, or in other words: the public API of your.jar.

Comments

1

Extract the class from jar file and then run

unzip my.jar 
find -name '*.class' | xargs javap -p > myjar.txt

The myjar.txt file will have all members inside the classes inside jar. You can search it for a method right after.

1 Comment

it is for linux/unix. this link may help testingfreak.com/run-unixlinux-commands-in-windows

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.