Search code examples
javaclassjvmbytecodejavah

I can't use javah -v XX to get the constant pool structure


I can't use javah -v XX to look the constant pool structure

the code:

public class Demo {
    private int m;

    public int plus() {
        return m + 1;
    }
}

execute javac Demo.java and generated the Demo.class

so, I type the command javah -v Demo, but an error has occurred:

Error: Could not find class file for 'Demo'.

I have tried javah -v Demo.class, but there is also an error message:

Exception in thread "main" java.lang.IllegalArgumentException: Not a valid class name: Demo.class
at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:177)
at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:68)
at com.sun.tools.javah.JavahTask.run(JavahTask.java:509)
at com.sun.tools.javah.JavahTask.run(JavahTask.java:335)
at com.sun.tools.javah.Main.main(Main.java:46)

but I want somthing like:

image

this is My javah path :

   /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/bin/javah

thank you very much!


Solution

  • To view class constant pool you need javap tool, not javah.

    If Demo.class is in current directory, specify . as the class path:

    javap -cp . -v Demo