I am trying to use JNA, because I want to work with a .dll that was written in c++ and the rest of my code is in Java. However, if I try to import the JNA classes Eclipse claims "The type com.sun.jna.Library is not accessible".
My IDE seems to see that JNA is somehow in my libraries because when I type "import com.sun.j" it proposes .jna and the other packages in the .jar files to me.
I have created a seperate Project to see if it works there, but it just doesnt work.
I have downloaded the latest .jar (jna-5.8.0.jar and jna-platform-5.8.0.jar) files from the jna Github (https://github.com/java-native-access/jna/blob/master/README.md ) and I have added them to the class path via project-> configure Buildpath -> add External JARs
I am using Eclipse with javaSE-13.
package Testtest;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
Package strcuture:
Test
|-- src
| |-- TestTest
| | |-- Main.java
| |-- module-info.java
|-- JRE System Library [JavaSE-13]
|-- Referenced Libraries
|-- jna-5.8.0.jar
|-- jna-platform-5.8.0.jar
As @greg-449 mentioned in the comments, you have a modular project, indicated by the presence of the module-info.java
file in your src
directory (package root).
You have three options here:
module-info.java
module-info.java
module descriptor in order to run your program without modulesmodule-info.java
) to add the directive requires com.sun.jna
. If you're using jna-platform
then also add requires com.sun.jna.platform
.
Structure
or PointerType
you will need to open
any packages in your project containing those subclasses to com.sun.jna
because they use reflection to access your subclasses. (There are multiple options here, but open TestTest to com.sun.jna
is the closest to JDK8 behavior.). I am aware this is just a test setup, but consider a reverse-DNS-style package name and module descriptor.jna-jpms-5.8.0
and jna-platform-jpms-5.8.0
JARs as your dependencies, as they have their own module descriptors.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With