Use JNI instead of JNA to call native code?

后端 未结 10 1991
滥情空心
滥情空心 2020-11-28 18:42

JNA seems a fair bit easier to use to call native code compared to JNI. In what cases would you use JNI over JNA?

相关标签:
10条回答
  • 2020-11-28 19:07

    Unless I'm missing something, isn't the main difference between JNA vs JNI that with JNA you can't call Java code from native (C) code?

    0 讨论(0)
  • 2020-11-28 19:08
    1. You are writing code a few years ago before there was JNA or are targeting a pre 1.4 JRE.
    2. The code you are working with is not in a DLL\SO.
    3. You are working on code that is incompatible with LGPL.

    That is only what I can come up with off the top of my head, though I am not a heavy user of either. It also seems like you might avoid JNA if you wanted a better interface than the one they provide but you could code around that in java.

    0 讨论(0)
  • 2020-11-28 19:08

    It's not a direct answer and I have no experience with JNA but, when I look at the Projects Using JNA and see names like SVNKit, IntelliJ IDEA, NetBeans IDE, etc, I'm tend to believe it's a pretty decent library.

    Actually, I definitely think I would have used JNA instead of JNI when I had to as it indeed looks simpler than JNI (which has a boring development process). Too bad, JNA wasn't released at this time.

    0 讨论(0)
  • 2020-11-28 19:11

    By the way, in one of our projects, we kept a very small JNI foot print. We used protocol buffers for representing our domain objects and thus had only one native function to bridge Java and C (then of course that C function would call a bunch of other functions).

    0 讨论(0)
提交回复
热议问题