jnat
A wrapper around the jni crate
View the documentation
Example
Create a new Cargo lib project with cargo new --lib mylib and add the following to Cargo.toml:
[]
= [latest version]
[]
= ["cdylib"]
Add the following to src/lib.rs:
use ;
pub extern "system"
Then, run cargo build. Create a new file called HelloWorld.java and add the following:
Compile the java file with javac -h . HelloWorld.java. Then, run java -Djava.library.path=path/to/target/debug HelloWorld. You should see Hello, world! printed to the console.
Notes
- Jnat re-exports jni by default. If you want to use a different version of jni, you can disable either the default features or the
jnifeature.