This repository contains sample Rust programs that call Java methods, and Java classes that call Rust methods.
-
sample000, call
Rustmethod fromJava -
sample001, convert
Javaprimitive types to bytes inRust -
sample002, accept a
Javaobject inRust, and callback toJava -
sample003, reverse
Javabytes -
sample004, access
JavaDirectBuffer inRust -
sample005, access
Javaprimitive array inRust -
sample006, create
Javaobject inRust -
sample007, set a field to
Javaobject inRust -
sample008, load
Javaclass inRusts008_class_buf.rsis generated by java2u8vec.sh -
sample009, register
Javamethod dynamically inRust
cargo build --releasecargo will generate .so in target/release, and call build_java.sh to build .jar, which contains .so in resources folder.
- call
Javaeach JUnit test in IDE - call
JavaJUnit test suite in IDE
Note: need to setup
JVMargs:-DsampleLib=<path to lib>
or
-
execute
Javaeach JUnit test in consolegradle test --tests HelloWorldTest -
execute
Javaeach JUnit test suite in consolegradle test --tests SamplesSuite
The JUnit report will be generated.
Thanks to metaworm(rust-java-demo). This article (url1/url2) is the most effective and detailed for learning how to call JNI through Rust.