Java本地方法封装库 JNA

jopen 13年前
     JNA(Java Native Access )提供一组Java工具类用于在运行期动态访问系统本地库(native library:如Window的dll)而不需要编写任何Native/JNI代码。开发人员只要在一个java接口中描述目标native library的函数与结构,JNA将自动实现Java接口到native function的映射。下面是一段使用该工具的示例代码:    <pre class="brush:java; toolbar: true; auto-links: false;">package com.sun.jna.examples;  import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.Platform;  /** Simple example of native library declaration and usage. */ public class HelloWorld {      public interface CLibrary extends Library {         CLibrary INSTANCE = (CLibrary)             Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"),                                CLibrary.class);             void printf(String format, Object... args);     }      public static void main(String[] args) {         CLibrary.INSTANCE.printf("Hello, World\n");         for (int i=0;i < args.length;i++) {             CLibrary.INSTANCE.printf("Argument %d: %s\n", i, args[i]);         }     } }</pre>    <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1324994393889" target="_blank">http://www.open-open.com/lib/view/home/1324994393889</a></p>