Package com. home; public class Testdll {// declare the name of the called database static {System. loadLibrary ("hello");} // make a local Declaration on the method to be called. The native keyword must be public native static int get (); public native static void set (int I); public static void main (String [] args) {Testdll test = new Testdll (); test. set (5); System. out. println (test. get ());}}
Program call to generate the required library file.
Note: first go to the src directory and then execute
/* DO NOT EDIT THIS FILE - it is machine generated */#include <jni.h>/* Header for class com_home_Testdll */#ifndef _Included_com_home_Testdll#define _Included_com_home_Testdll#ifdef __cplusplusextern "C" {#endif/* * Class: com_home_Testdll * Method: get * Signature: ()I */JNIEXPORT jint JNICALL Java_com_home_Testdll_get (JNIEnv *, jclass);/* * Class: com_home_Testdll * Method: set * Signature: (I)V */JNIEXPORT void JNICALL Java_com_home_Testdll_set (JNIEnv *, jclass, jint);#ifdef __cplusplus}#endif#endif
JNIEXPORT jint JNICALL Java_com_home_Testdll_get (JNIEnv *, jclass );
#include "com_home_Testdll.h" int i = 0; JNIEXPORT jint JNICALL Java_com_home_Testdll_get (JNIEnv *, jclass) { return i; } JNIEXPORT void JNICALL Java_com_home_Testdll_set (JNIEnv *, jclass, jint) { i = j; }