How to Use JNI: How to Use JNI
1. in java, public native void + method name ("");
2. Then load the required underlying so file system. loadLibrary ("so file name cannot be suffixed ")
3. When you need to call the native method, you can call it as a normal method.
The following is the implementation of the underlying C or C ++
1. Find the directory where your project is located and open cmd to enter the directory where your project is located
2. javac-d. Add the class name of your native class. java
2. Generate the header file using the javah + class name
3. paste the header file, that is, the. h file, to the directory where your C implementation code is located.
4. Then introduce the header file # include "file name. h" on your C file"
5. Then introduce the jni. h file C: \ Program Files (x86) \ Java \ jdk1.6.0 _ 10 \ include.
And C: \ Program Files (x86) \ Java \ jdk1.6.0 _ 10 \ include \ win32 jni_md.h Files
Open jni. h. If you find that jni_md.h has been introduced, you do not need to introduce it on C.
6. Then, import the system output # include <stdio. h>. Note that angle brackets represent the system directory, and double quotation marks represent the current directory.
7. Copy the C code method to be implemented in. h to C, change the semicolon to braces, and write the logic to be implemented in it.
8. Then, compile ctrl + shift + d.
9. Then, go to the directory compiled by C code to find the. c file you have produced, and copy it to \ Program Files (x86) \ Java \ jdk1.6.0 _ 10 \ bin.
10 note that the so file name referenced in java must be the same as the so file name generated by you.