将 JNA 与 IBM J9 JVM 结合使用

发布于 2024-11-08 05:55:22 字数 1872 浏览 5 评论 0原文

将 JNA 与 J9 一起使用的第一个困难是 J9 JVM 不包含 java.awt 包,并且 Native 类从该包导入一些类。通过下载 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 版本”是什么意思?有人让 J9 与 JNA 配合得很好吗?

更新:我认为 JNA 在尝试加载 java.nio.Buffer 类时会抑制以下 NoClassDefFoundError ,因为 J9 显然没有包含 NIO 包:

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)

The first difficulty in using JNA with J9 is that the J9 JVM does not include the java.awt package and the Native class imports a few classes from this package. This is easily overcome by downloading the JNA source, ripping out these imports and their dependent methods (which I am not using anyway), and building 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[] {});
        }

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

After correcting the java.awt problem, I receive the error:

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 it mean by "Incompatible JNI version"? Has anybody out there got J9 to play nice with JNA?

UPDATE: I think JNA is suppressing the following NoClassDefFoundError on trying to load the java.nio.Buffer class because J9 apparently does not have the NIO package included:

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜还是长夜 2024-11-15 05:55:22

我已经与 JNA 合作开发 j9 几个月了。我到处都遇到了一些小问题,但大多数情况看起来都运行良好。

首先 - 最新版本的 JNA(3.2.7) 似乎导入了 awt。我使用的是 3.2.4 并且 awt 导入被注释掉了。我认为这对你来说是开箱即用的。

其次 - 我正在使用的 J9 版本是针对 WinCE 的,它是针对 java 1.4 的 JVM。最新的 JNA 是基于 java 1.5 构建的。因此,您可能需要检查您的 j9 版本是基于哪个版本的 java 构建的。我相信 JNA 3.2.4 与 java 1.4 兼容。

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.

计㈡愣 2024-11-15 05:55:22

您还可以简单地提供您自己的 java.nio/java.awt 内容的存根实现,并简单地避免使用这些功能(主要是直接缓冲区内容并获取本机窗口的句柄)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文