其中JAVA源程序为:
public class testdll 
{ static 
  { System.loadLibrary("goodluck"); 
  } 
  public native static int get(); 
  public native static void set(int i); 
  public static void main(String[] args) 
  { testdll test = new testdll(); 
    test.set(10); 
    System.out.println(test.get()); 
  } 
} 编译之后,用javah生成了testdll.h文件。该文件信息为:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class testdll */#ifndef _Included_testdll
#define _Included_testdll
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     testdll
 * Method:    get
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_testdll_get
  (JNIEnv *, jobject);/*
 * Class:     testdll
 * Method:    set
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_testdll_set
  (JNIEnv *, jobject, jint);#ifdef __cplusplus
}
#endif
#endif
然后用C++Builder编辑goodluck.dll文件,源程序为:
#include "testdll.h"
#include <stdio.h>
int i=0;
JNIEXPORT jint JNICALL Java_testdll_get (JNIEnv *, jclass) 

  return i; 

JNIEXPORT void JNICALL Java_testdll_set (JNIEnv *, jclass, jint j) 

  i = j; 
}
之后将编译成的DLL文件放到原工程目录中运行,JBUILDER7运行时出错,错误信息为:
java.lang.UnsatisfiedLinkError: set
at pktest.testdll.set(Native Method)
at pktest.testdll.main(testdll.java:22)
Exception in thread "main"