1.编写 native 接口
public class JavaUseC {
public native int sum(int a,int b);
public native int max(int a,int b);
public native int min(int a,int b);
public native String getStudentName(Student student);
public native byte[] getStudentAddress(Student student);
public native int getStudentAge(Student student);
public native Student getStudent(String name, int age, byte[] address);
}
- 生成 c 的头文件
cd /d D:\java\iristar-algorithm\src\main\java
javah -jni -encoding UTF-8 com.iristar.center.algorithm.face.jni.FaceJNIV22
3.编写 c 的dll,注意java和c的类型转换
4.调用 jni接口
JavaUseC tNative = new JavaUseC();
System.out.println("tNative.sum(10,20): "+tNative.sum(10,20));
System.out.println("tNative.max(10,20): "+tNative.max(10,20));
System.out.println("tNative.min(10,20): "+tNative.min(10,20));