通过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
转载于:https://blog.51cto.com/whithin/1174645