2007-06-1210:53JNI=javanativeinterface,为java应用程序提供调用本地方法的接口 ThestandardJavaclasslibrarymaynotsupporttheplatform-dependentfeaturesneededbyyourapplication. essibletoJavaapplications. Youmaywanttoimplementasmallportionoftime-criticalcodeinalower-levelprogramminglanguage,suchasassembly,andthenhaveyourJavaapplicationcallthesefunctions 步骤: jni;public class HelloWorld { static{ ("hellodll"); } public native void dispHelloWorld(); /** * ***@param args */ public static void main(String[]args) { // TODOAuto-generatedmethodstub //("abc"); new HelloWorld().dispHelloWorld(); }}2,保存后如果没有错误eclipse会编译产生jni/,假设工程产生的class都在classes文件夹下(这个文件夹名字跟个人eclipse设置有关,也可能就是工程根目录),那么控制台cd到classes用javah命令产生h文件,XXX/classes>javah-(package不要漏掉),/* DONOTEDITTHISFILE-itismachinegenerated */#include <>/* Headerforclassjni_HelloWorld */#ifndef_Included_jni_HelloWorld#define _Included_jni_HelloWorld#ifdef__cplusplusextern "C" {#endif/* *Class: jni_HelloWorld *Method: dispHelloWorld *Signature:()V */JNIEXPORT void JNICALLJava_jni_HelloWorld_dispHelloWorld (JNIEnv *,jobject);#ifdef__cplusplus}#endif#endif4,写cpp,,这里请注意函数名,cpp里的函数名跟h文件的函数名要一致,如果是
eclipse下jni初试 来自淘豆网m.daumloan.com转载请标明出处.