第一步,在idea中,编写java文件,并且编译
package jni; public class HelloWorld { static { System.loadLibrary("HelloWorld"); } public native static void say(String content); public static void main(String[] args) { HelloWorld.say("JNI native Hello World!"); } }
第二步在idea中,浏览class文件进入D:wksp_studydesignbook argetclasses 目录,这个目录下边就是包名文件
在这个文件中打开cmd,D:wksp_studydesignbook argetclasses>javah -classpath D:wksp_studydesignbook argetclasses jni.HelloWorld
生成jni_HelloWorld.h文件头
/* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class jni_HelloWorld */ #ifndef _Included_jni_HelloWorld #define _Included_jni_HelloWorld #ifdef __cplusplus extern "C" { #endif /* * Class: jni_HelloWorld * Method: say * Signature: (Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_jni_HelloWorld_say (JNIEnv *, jclass, jstring); #ifdef __cplusplus } #endif #endif