package com.mytest;public class test
{static {System.loadLibrary("testJni");}public static native int helloworld(String str);
}
命令行下编译:
javac test.java
使用javah生成jni头文件
javah -classpath E:\code\eclipse-project\test\src com.mytest.test
此处要注意-classpath 是package所在目录,之后跟的是package+类名(不带扩展名)
生成头文件:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include
/* Header for class com_mytest_test */#ifndef _Included_com_mytest_test
#define _Included_com_mytest_test
#ifdef __cplusplus
extern "C" {
#endif
/** Class: com_mytest_test* Method: helloworld* Signature: (Ljava/lang/String;)I*/
JNIEXPORT jint JNICALL Java_com_mytest_test_helloworld(JNIEnv *, jclass, jstring);#ifdef __cplusplus
}
#endif
#endif