Registry / other / jni
library0.22.4rscratesunverified

Rust bindings to the Java Native Interface (JNI) for calling Java code from Rust and vice versa.

# Cargo.toml [dependencies] jni = "0.22.4"
INSTALL
IMPORT
SIG · JNI
J
jni
otherrustv0.22.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JNIEnv
✓ use jni::JNIEnv;

Defines a JNI function that creates a Java string and prints it via System.out.

use jni::JNIEnv; use jni::objects::JClass; #[no_mangle] pub extern "system" fn Java_HelloWorld_hello(env: JNIEnv, _class: JClass) { let output = env.new_string("Hello from Rust!").unwrap(); env.call_static_method("java/lang/System", "out", "()Ljava/io/PrintStream;", &[]).unwrap(); }
Debug
Known issues
gotchaJNI functions must have the exact naming convention and be compiled as a cdylib.
fix
Set crate-type = ["cdylib"] in Cargo.toml and ensure function names match Java package paths.
affects: >=0.20.0
Upgrade
Version history
0.22.4latest on crates.io
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
jni — cargo add jni · libregistry