public class JNITest {
static {
System.loadLibrary(“DwgOperInterface”);
}
public native String getDllFunction();
public native String transObject(MapController mapController);
public static void main(String[] args) {
new JNITest().getDllFunction();
}
}
注:DwgOperInterface为dll文件的名称,建议放在jdk BIN文件夹下
第二步:生成JNITest.h头文件
CMD控制台,切换到src/main/java 文件夹下,输入生成头文件命令,在该文件夹下生成头文件
javah -encoding utf-8 -classpath . -jni com.hxtx.spacedata.controller.map.JNITest
第三步:用c语言代码实现生成头文件里的接口
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_hxtx_spacedata_controller_map_JNITest */
#ifndef _Included_com_hxtx_spacedata_controller_map_JNITest
#define _Included_com_hxtx_spacedata_controller_map_JNITest
#ifdef __cplusplus
extern “C” {
#endif
/*
-
Class: com_hxtx_spacedata_controller_map_JNITest
-
Method: getDllFunction
-
Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_hxtx_spacedata_controller_map_JNITest_getDllFunction
(JNIEnv *, jobj
ect);
/*
- Class: com_hxtx_spacedata_controller_map_JNITest