質問

J9とJNAを使用することの最初の難易度は、J9JVMにjava.awtパッケージを含まないこと、およびネイティブクラスはこのパッケージからいくつかのクラスをインポートしていることです。これは、JNAソースをダウンロードし、これらの輸入方法とその依存方法(とにかく使用していない)をリッピングし、新しいJNA JARを構築することで簡単に克服します。

これは簡単なテストプログラムです:

    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);
        }
    }
.

java.awt問題を修正した後、エラーを受け取ります:

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)
.

「互換性のないJNIバージョン」とはどういう意味ですか?誰かがJNAでうまく遊ぶためにJ9を持っていますか?

UPDATE:JNIO.NIO.NIO.BUFFERクラスをロードしようとしている次のNoClassDeffoundErrorを抑制していると思います:

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)
.

役に立ちましたか?

解決

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.

他のヒント

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).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top