5 ms·
Why would I use it over JNI? I used JNI few times and it was very easy and straightforward. Can I use it to call any WinAPI without C glue?
by vbezhenar 5y ago
Why would I use it over JNI? I used JNI few times and it was very easy and straightforward.
Can I use it to call any WinAPI without C glue?
- throwawayninja 5y agoJNI => "I write C code & after compilation java can access it as com.package.ClassName" JNA => "I write java code & load libsomething at runtime, asking for FuncName(int, int) which java can then call into native code." You want JNA for your use case.
- geokon 5y agoSo what is the difference between this and JNA? I assume it's not the same since it's taking a while to be added to the language
- pie_flavor 5y agoJNI is the only escape hatch in the JRE. JNA leverages JNI and so has a better API while still keeping the terrible performance. This is like JNA, but more robust, and while also being an escape hatch of its own so that you can finally get performance similar to P/Invoke when making native calls.
- chakkepolja 5y agoThis is apparently focused on efficiently accessing off-heap memory. In Jni lot of things require copies. Only JNI API that's reliably copy-free is ByteBuffer API.
- danhau 5y agoRead under `Motivation`, I think it answers your question. Of course you can still use JNI.
- chrisseaton 5y agoJNI requires you to write your own C code to call into. I generally want to do that as little as possible, for many reasons (I’d have to build it and ship it myself.)
- grishka 5y agoJNI is extremely tedious. Not only do you have to have a native library built for every platform you support, you also have to manually convert between Java and C representations of things. A lot of glue code for which there are no generators (I think). JNA is better, it still relies on JNI, but uses a tiny stub library to allow you to link to and call arbitrary functions from C dynamic libraries in pure Java. This feature is basically JNA, but more efficient and built into the JVM itself.