0% found this document useful (0 votes)
252 views

Java Native Access

This document provides steps to configure the Java Native Access (JNA) library in Eclipse: 1. Download and add the JNA (jna.jar) and JNA Platform (jna-platform.jar) libraries to the Eclipse build path. 2. Create a new library entry in Eclipse for the JNA libraries and add the downloaded JNA and JNA Platform jars. 3. Test the JNA configuration with a simple Hello World example that prints output using the CLibrary interface to native C functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
252 views

Java Native Access

This document provides steps to configure the Java Native Access (JNA) library in Eclipse: 1. Download and add the JNA (jna.jar) and JNA Platform (jna-platform.jar) libraries to the Eclipse build path. 2. Create a new library entry in Eclipse for the JNA libraries and add the downloaded JNA and JNA Platform jars. 3. Test the JNA configuration with a simple Hello World example that prints output using the CLibrary interface to native C functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

‫ السالم عليكم‬,

 If you are using eclipse its very simple


I have tested it on a project
Before configuration :

 Configuration:
Step 1:
We need to install library jna.jar
https://repo1.maven.org/maven2/net/java/dev/jna/jna/5.6.
0/jna-5.6.0.jar

Step 2:

We need to install library jna-platform.jar  her is the link

“https://repo1.maven.org/maven2/net/java/dev/jna/
jna-platform/5.6.0/jna-platform-5.6.0.jar”

Step 3: add this libraries to eclipse ,


Propriety ==>java build path ==> libraries
From here we add a new library name it for example: jna_lab
And We ADD the two-external library that we have installed jna.jar
and ,jna-platform.jar  

This is the result final it works ,


This is the code I used
1. package com.sun.jna.examples;
2.  
3. import com.sun.jna.Library;
4. import com.sun.jna.Native;
5. import com.sun.jna.Platform;
6.  
7. /** Simple example of JNA interface mapping and usage. */
8. public class HelloWorld {
9.  
10. // This is the standard, stable way of mapping, which supports
extensive
11. // customization and mapping of Java to native types.
12.  
13. public interface CLibrary extends Library {
14. CLibrary INSTANCE = (CLibrary)
15. Native.load((Platform.isWindows() ? "msvcrt" : "c"),
16. CLibrary.class);
17.  
18. void printf(String format, Object... args);
19. }
20.  
21. public static void main(String[] args) {
22. CLibrary.INSTANCE.printf("Hello, World\n");
23. for (int i=0;i < args.length;i++) {
24. CLibrary.INSTANCE.printf("Argument %d: %s\n", i, args[i]);
25. }
26. }
27. }

You might also like