[vc_row][vc_column][vc_column_text]
JNA (Java Native Access) provides a group of Java tools used to dynamic access local system library when running (native library: such as DLL under windows) and do not need to write any Native/JNI code. Developer just need to describe the function and structure of target native library in the java interface , the JNA will automatically implement the mapping from Java interface to native function.
Advantage
JNA could make it possible for you to directly call the native method just like call the general java. It is almost the same as the directly call the local method, and call the local method which does not need other processes or configure, as well as other extra reference or coding, and it is very convenient to use.
Java description:
JNA library uses a very small local library sub to dynamically call the local code. The programmer only need to use the specify java interface description.[/vc_column_text][vc_tour][vc_tab title=”Use the JNA under the Windows” tab_id=”1395035631-1-40″][vc_column_text]1.Download the jna.jar
2.Create the project JNA under the eclipse
3.Import the jna.jar package to the project
4.Create the test class and write it into the code
import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.Platform; public class JNA_test { public interface CLibrary extends Library { CLibrary Instance=(CLibrary)Native.loadLibrary("msvcrt",CLibrary.class); void printf(String format, Object... args); } public static void main(String[] args) { CLibrary.Instance.printf("Hello, JNA!n"); } }
[/vc_column_text][/vc_tab][vc_tab title=”Results” tab_id=”1395035631-2-13″][vc_column_text]Run and output at the console.
[/vc_column_text][/vc_tab][vc_tab title=”Test code” tab_id=”1395039549981-2-0″][vc_column_text]
import com.sun.jna.Library; import com.sun.jna.Native; public class JNA_test { public interface CLibrary extends Library { CLibrary Instance=(CLibrary)Native.loadLibrary("msvcrt", CLibrary.class); void printf(String format, Object... args); } public static void main(String[] args) { CLibrary.Instance.printf("Hello, JNA!n"); // System.out.println(Platform.isARM()); } } Create the test class JNA_test and write the code into it.
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.