Proper way of Java interop/FFI?

What is the proper way of doing Java interop / FFI to avoid tons of useless boilerplate code.

Playgrund with sample of code

Something better than that? Did anyone use jafi?

I came across this blog post.

Assuming the article is correct (it's from okta.com, so that's likely), it shows that since my Java days (in which JNI was basically state of the art) with Panama FFI has finally been taken more seriously by the JVM people.

1 Like

I've used GitHub - astonbitecode/j4rs: Java for Rust to call Java from Rust and it was fairly painless and has worked well. It supports calling Rust from Java as well but I haven't tried that.

1 Like

Check out JNI crate

1 Like

What is preferred way of doing it? JNI?

I don't really know cuz i'm not a Java enjoyer. All i can tell you is that jni is a good crate usually used for "touching" JRE :slight_smile:

1 Like

Using JNI is still the standard way to do FFI with Java. If you have control of what version of Java your code will be running with, you may be able to use the Project Panama APIs that aim at improving FFI with Java over the old JNI style as mentioned here

If you can't arbitrarily choose what Java version your code will run against, you will probably need to use JNI. Though you are of course free to use one of the tools that aims to abstract away some of the JNI's complexity rather than using the plain jni crate directly

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.