Article Directory
JNI
JNI is the abbreviation of Java Native Interface. By using the Java native interface to write programs, you can ensure that the code is easily transplanted on different platforms.
Example
Use vs2013 to build dll dynamic library in windows environment.
Build so dynamic library in liunx environment.
Use System.load to load the dynamic library in the java project.
Complete a simple demo based on the above tutorial.
Precautions
Build dll in windows environment
1. Execute javah -jni cn.weezoo.jnademo.NativeCpp in classes to generate header files.
2. Find jni.h and jni_md.h in the jdk/include directory
3. Set the debugging environment of vs2013 to x64
4 , Write related implementation code
5. Generate solutions.
Build so in linux environment
1. Execute javah -jni cn.weezoo.jnademo.NativeCpp in classes to generate header file.
2. Find include in jdk installation path (/usr/lib/jvm/java-1.8.0-openjdk-1.8 .0.282.b08-1.el7_9.x86_64)
3. Replace the position in the makefile
4. Write hello.cpp to implement cn.weezoo.jnademo.NativeCpp.h
5. Execute the make command to generate the so file
6. Pay attention to modify the Linux in the project Path to load the so file