The first difficulty with using JNA with J9 is that the J9 JVM does not include the java.awt package, and the Native class imports several classes from this package. This is easily overcome by downloading the JNA source, ripping out these imports and their dependent methods (which I don't use yet) and creating a new JNA jar.
Here is a simple test program:
public class TestJni {
public static void main(String[] args) {
CLibrary instance = (CLibrary) Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"), CLibrary.class);
instance.printf("Hello, World\n", new Object[] {});
}
public interface CLibrary extends Library {
void printf(String format, Object[] args);
}
}
After fixing the java.awt problem, I get the error message:
Caused by: java.lang.UnsatisfiedLinkError: C:\DOCUME~1\TSO0112\LOCALS~1\Temp\jna72681.dll (Incompatible JNI version (not 1.1, 1.2 or 1.4))
at java.lang.ClassLoader.loadLibraryWithPath(ClassLoader.java:973)
at java.lang.System.load(System.java:459)
at com.sun.jna.Native.loadNativeLibraryFromJar(Native.java:696)
at com.sun.jna.Native.loadNativeLibrary(Native.java:620)
at com.sun.jna.Native.<clinit>(Native.java:104)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:187)
at TestJni.main(TestJni.java:8)
What does "Incompatible JNI Version" mean? Does anyone have a J9 to play with JNA?
UPDATE: I think JNA suppresses the following NoClassDefFoundError when trying to load the java.nio.Buffer class, because J9 does not seem to have the NIO package:
JNA: Problems loading core IDs: java.nio.Buffer
Exception in thread "main" java.lang.NoClassDefFoundError: java.nio.Buffer
at java.lang.ClassLoader.loadLibraryWithPath(Native Method)
at java.lang.ClassLoader.loadLibraryWithPath(ClassLoader.java:965)
at java.lang.System.load(System.java:459)
at TestJni.main(TestJni.java:8)
source
share