This repository contains sample Rust programs that call Java methods, and Java classes that call Rust methods.
sample000, call
Rustmethod fromJavasample001, convert
Javaprimitive types to bytes inRustsample002, accept a
Javaobject inRust, and callback toJavasample003, reverse
Javabytessample004, access
JavaDirectBuffer inRustsample005, access
Javaprimitive array inRustsample006, create
Javaobject inRustsample007, set a field to
Javaobject inRustsample008, load
Javaclass inRusts008_class_buf.rsis generated by java2u8vec.shsample009, 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 HelloWorldTestexecute
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.