Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use javap

I must be doing something stupid, because this seems like such a easy operation. For some reason, I just cannot get this command to work for me. I've installed JDK, and I go into the

/bin

folder. I type:

./javap -classpath /home/Matt/workspace/VariablesTestProject/src/ -s VariablesTest.Variable

My actual filepath for the class is

/home/Matt/workspace/VariablesTestProject/src/VariablesTest/Variable.java

The error I get back is:

ERROR:Could not find VariablesTest.Variable

A command like this works however:

./javap -s java.lang.String

These are not the only commands I've tried. I've literally tried every variation I can think of, and none of them work. My javac and java commands both work fine.

Any suggestions?

like image 905
KWJ2104 Avatar asked Jul 11 '12 17:07

KWJ2104


People also ask

What does Javap stand for?

javap is part of the official Java tools and allows to disassemble one or more class files. The "p" in this case stands for print, as in the official documentation is reported that: ... the javap command prints 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.


2 Answers

Javap works against the .class bytecode. So point the classpath at the VariablesTestProject/out or whatever.

like image 165
Dilum Ranatunga Avatar answered Nov 06 '22 10:11

Dilum Ranatunga


If you want perform operations using the javap command, first go to the jar location in cmd prompt.

Eg:

cd /usr/lib/jvm/java-6-openjdk-i386/jre/lib (Linux)

cd D:\javasoftware\Java\jdk1.6.0_43\jre\lib (Windows)

The above locations are the rt.jar locations. java.lang.String is the one of the classes in this jar.

Using javap you can get the information from this class.

Eg:

cd /usr/lib/jvm/java-6-openjdk-i386/jre/lib
javap java.lang.String 
like image 3
Murali Avatar answered Nov 06 '22 08:11

Murali