Javah tool error: Could not find class file for hellojni

后端 未结 6 1270
無奈伤痛
無奈伤痛 2020-12-13 13:46

I am trying to create a header file using javah tool from command line on windows 7 OS but i am failing all the time.

I have followed different ways and even read t

6条回答
  •  渐次进展
    2020-12-13 13:55

    I suspect the issue is that your class has a package and you are trying to run the command from the directory with the class file instead of the package root.

    Samhain's example works because his MyClass.java contains no package, whereas I suspect yours does.

    For example, assume we have the following file at c:\src\com\example\MyClass.java

    package com.example;
    
    public class MyClass {
        public native void myMethod();
    }
    

    Go to the command line and execute the following:

    c:\src\com\example>javac MyClass.java
    
    c:\src\com\example>dir
    
     Directory of C:\src\com\example
    
    2015-02-23  03:17 PM              .
    2015-02-23  03:17 PM              ..
    2015-02-23  03:20 PM               219 MyClass.class
    2015-02-23  03:17 PM                84 MyClass.java
    
    c:\src\com\example>javah MyClass
    Error: Could not find class file for 'MyClass'.
    
    c:\src\com\example>cd c:\src
    
    c:\src>javah com.example.MyClass
    
    c:\src>dir
     Directory of C:\src
    
    2015-02-23  03:18 PM              .
    2015-02-23  03:18 PM              ..
    2015-02-23  03:16 PM              com
    2015-02-23  03:18 PM               449 com_example_MyClass.h
    

    Success!

提交回复
热议问题