test文件夹下JniTest.java内容

package test;
public class JniTest
static{
System.setProperty("java.library.path", "/home/tong.guo/cpp-text-match/bin");
System.load("/home/tong.guo/cpp-text-match/bin/libXgboostTextMatch.so");
}
private native long loadXgboostModel(String modelPath,int threadNum);
private native float xgboostScore(long pointToHandler,String q1,String q2);
private native void releaseXgboostModel(long pointToHandler);

public static void main(String args[]){

JniTest test=new JniTest();
long h = test.loadXgboostModel("/home/tong.guo/cpp-text-match/my_df/",10);
float score = test.xgboostScore(h, "大家好", "大家好吗");
System.out.println(score);
test.releaseXgboostModel(h);
}
}

以UTF-8无BOM格式编码,

在test文件夹平行目录,
先编译:

javac -encoding UTF-8 test/JniTest.java

生成h头文件:

javah -jni -classpath . -encoding UTF-8 test.JniTest