Question

La première difficulté à utiliser la JNA avec J9 est que le J9 JVM n'inclut pas le package Java.awt et la classe natale importe quelques classes de ce paquet.Ceci est facilement surmonté en téléchargeant la source de la JNA, déchirant ces importations et leurs méthodes dépendantes (que je n'utilise pas de toute façon) et construisant un nouveau pot de JNA.

Voici un programme de test simple:

    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[] {});
        }

        // This is the standard, stable way of mapping, which supports extensive
        // customization and mapping of Java to native types.
        public interface CLibrary extends Library {        
            void printf(String format, Object[] args);
        }
    }

Après avoir corrigé le problème Java.awt, je reçois l'erreur:

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)

Qu'est-ce que cela signifie par "Version JNI incompatible"?Quelqu'un est-il sorti de J9 pour jouer sympa avec JNA?

MISE À JOUR: Je pense que la JNA supprimait le NOCLassDEffondError suivant en essayant de charger la classe Java.NIO.Buffer, car J9 n'a apparemment pas le package Nio inclus:

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)

Était-ce utile?

La solution

I have been working with JNA on j9 for a couple of months now. I have had a few small niggles here and there but things mostly seem working fine.

First - The latest versions of JNA(3.2.7) seem to import awt. I am using 3.2.4 and the awt imports are commented out. I think that will work out of the box for you.

Second - THe version of J9 i am working with is for WinCE and it is a JVM for java 1.4. Latest JNA though is built off of java 1.5. So you might want to check which version of java your version of j9 is built on. JNA 3.2.4 is compatible with java 1.4 I believe.

Autres conseils

You can also simply provide your own stub implementations of the java.nio/java.awt stuff and simply avoid using those features (mainly direct buffer stuff and obtaining a handle to a native window).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top