Javah error while using it in JNI

前端 未结 14 1710
离开以前
离开以前 2020-12-01 05:27

Command:

javah -jni JavaHowTo

Result:

error: cannot access JavaHowTo 
class file for JavaHowTo not found

javadoc: error -          


        
14条回答
  •  半阙折子戏
    2020-12-01 05:48

    issue on Cygwin:

    javah does not work properly from Cygwin terminal:

    $ cd /cygdrive/c/Workspace/prj/bin
    $ ls com/example/JavaHotTo.class
    com/example/JavaHotTo.class
    $ javah com.example.JavaHowTo
    Error: Could not find class file for 'com.example.JavaHowTo'.
    

    But it works perfectly using the option -classpath .

    $ javah -classpath . com.example.JavaHowTo
    $ ls *.h
    com_example_JavaHotTo.h
    

    More tricks:

    • The option -jni is by default, therefore it is not require.
    • You can give relative/absolute classpath
    • But javah on MS-Windows prefers path à la C:\Workspace\prj\bin
    • Use cygpath -w /cygdrive/c/Workspace/prj/bin to convert into MS-Windows format
    • Use option -d your/jni/headers/path to write headers in another directory
    • javah creates the path your/jni/headers/path if it does not exist (see below)

      $ javah -d jni/headers -classpath . com.example.JavaHowTo
      $ ls       jni\headers
      com_example_JavaHotTo.h
      $ javah -d jni\path -classpath . com.example.JavaHowTo
      $ ls       jni\path
      com_example_JavaHotTo.h
      

提交回复
热议问题