通過javah可以自動生成相應的JNI的.h文件,運行“javah -help” 命令顯示用法如下:
- Z:\>javah -help
- Usage: javah [options] <classes>
- where [options] include:
- -help Print this help message and exit
- -classpath <path> Path from which to load classes
- -bootclasspath <path> Path from which to load bootstrap classes
- -d <dir> Output directory
- -o <file> Output file (only one of -d or -o may be used)
- -jni Generate JNI-style header file (default)
- -version Print version information
- -verbose Enable verbose output
- -force Always write output files
- <classes> are specified with their fully qualified names (for instance, java.lang.Object).
example:
hello-jni應用程序所在目錄爲F:\hello-jni, 編譯生成的class文件在bin\classes文件夾下,那麼調用javah時的classpath 必須指向該路徑
第一種情況:
F:\hello-jni>javah -classpath bin/classes com.example.hellojni.HelloJni
在應用程序根目錄下,那麼classpath 的相對路徑爲 bin/classes
第二種情況:
F:\hello-jni\bin>javah -classpath classes com.example.hellojni.HelloJni
在bin目錄下,那麼classpath的相對路徑爲 classes
第三種情況:
F:\hello-jni\bin\classes>javah -classpath . com.example.hellojni.HelloJni
在classes目錄下,那麼classpath應該爲當前目錄,即 .
第四種情況:
F:\temp>javah -classpath F:\hello-jni\bin\classes com.example.hellojni.HelloJni
此時classpath 應該指向classes所在的絕對路徑,即F:\hello-jni\bin\classes