1,建立测试类,注意英文注释部分,用汉语直接编译会乱码
public classHello {//native method is used for call other language procedure//if use chinese here then Compile would be gibberish
public native voidprintHello();static{
System.loadLibrary("HelloWorld");//加载生成的dll文件
}public static voidmain(String[] args) {newHello().printHello();
}
}
2,编译
javac Hello.java
3,生成.h文件(.h文件为C语言的头文件,内含函数声明、宏定义、结构体定义等内容)
javah Hello
.h文件内容
/* DO NOT EDIT THIS FILE - it is machine generated */
#include
/* Header for class Hello */
#ifndef _Included_Hello
#define _Included_Hello
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Hello
* Method: printHello
* Signature: ()V
*/
JNIEXPORT void JNICALL J