Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I print the class structures in a jar file using the javap tool?

Tags:

I want to list the methods of the class files in the jar using the javap tool. How do I do it so that it lists the methods and members of all the class files in the jar. Right now I am able to do it for just one class at a time.

I am expecting something like if I say

javap java.lang.* 

it should enlist the methods and members of all the classes in java.lang package. If javap is not capable of that, are there any such tools available?

like image 883
Prabhu R Avatar asked Jul 23 '09 13:07

Prabhu R


People also ask

What is use of Javap tool in Java?

The javap command disassembles one or more class files. Its output depends on the options used. If no options are used, javap prints out the package, protected, and public fields and methods of the classes passed to it.

How do I view the contents of a class file?

A simple way to see what String literals are used in a ". class" file is to use the javap utility in your JDK installation to dump the file using the "-v" option. Then grep for text that looks like <String "..."> where ... is the String you are looking for.

Which command disassembles a class file the Javap command displays information about the fields constructors and methods present in a class file?

The javap command disassembles a class file. The javap command displays information about the fields, constructors and methods present in a class file.


1 Answers

#!/bin/bash # Set the JAR name jar=<JAR NAME> # Loop through the classes (everything ending in .class) for class in $(jar -tf $jar | grep '.class'); do      # Replace /'s with .'s     class=${class//\//.};     # javap     javap -classpath $jar ${class//.class/};  done 
like image 81
David Grant Avatar answered Nov 07 '22 08:11

David Grant