JNI, The Java Native Interface
 
用于编写Java本机方法和将Java虚拟机嵌入本机应用程序的标准编程接口。

网站:http://download.oracle.com/javase/6/docs/technotes/guides/jni/index.html,http://java.sun.com/docs/books/jni/
支持平台:Win32,Linux
标题包括:jni.bi
标题版本:2006年
示例:在examples / other-languages / Java /

例子


三个文件:

  • mylib.bas - 一个写入FreeBASIC的DLL

#include "jni.bi"
    
'' Note: The mangling must be "windows-ms" or the JRE won'找到任何功能
Extern "Windows的MS"
    Function Java_MyLib_add( env As JNIEnv Ptr, obj As jobject, l As jint, r As jint ) As jint Export
        Return l + r
    End Function
End Extern


  • Mylib.java - 代表FreeBASIC代码接口并确保FreeBASIC DLL加载的Java类

(cpp)
class MyLib {
 public native int add( int l, int r );
 static {
  System.loadLibrary( "mylib" );
 }
}

  • Test.java - 使用Mylib类的Java main()

(cpp)
class Test {
 public static void main(String[] args) {
  MyLib lib = new MyLib();
  System.out.println( "2+2=" + lib.add( 2, 2 ) ); 
 }
}

测试步骤:

  • Compile the FreeBASIC DLL: fbc mylib.bas -dll
  • Compile the two Java classes: javac Mylib.java Test.java
  • Run the Test class: java测试