This repository contains sample Rust
programs that call Java
methods, and Java
classes that call Rust
methods.
-
sample000, call
Rust
method fromJava
-
sample001, convert
Java
primitive types to bytes inRust
-
sample002, accept a
Java
object inRust
, and callback toJava
-
sample003, reverse
Java
bytes -
sample004, access
Java
DirectBuffer inRust
-
sample005, access
Java
primitive array inRust
-
sample006, create
Java
object inRust
-
sample007, set a field to
Java
object inRust
-
sample008, load
Java
class inRust
s008_class_buf.rs
is generated by java2u8vec.sh -
sample009, register
Java
method dynamically inRust
cargo build --release
cargo
will generate .so
in target/release
, and call build_java.sh
to build .jar
, which contains .so
in resources
folder.
- call
Java
each JUnit test in IDE - call
Java
JUnit test suite in IDE
Note: need to setup
JVM
args:-DsampleLib=<path to lib>
or
-
execute
Java
each JUnit test in consolegradle test --tests HelloWorldTest
-
execute
Java
each 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
.