السالم عليكم,
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. }