typed-jni-core

Crates.iotyped-jni-core
lib.rstyped-jni-core
version1.1.4
created_at2025-10-20 17:45:19.742907+00
updated_at2026-01-13 12:48:42.567818+00
descriptionType-Safe JNI access for Rust.
homepagehttps://github.com/Kr328/typed-jni-rs
repositoryhttps://github.com/Kr328/typed-jni-rs
max_upload_size
id1892397
size110,558
Kr328 (Kr328)

documentation

README

Basic JNI Bindings for Rust

crates.io docs.rs

This crate provides basic JNI bindings for Rust.

Example

use typed_jni_core::{Arg, FieldID, JNIEnv, LocalRef, MethodID};

pub fn run_jni(env: &JNIEnv) {
    unsafe {
        let c_system = env.find_class(c"java/lang/System").unwrap();

        let f_out: FieldID<true> = env.get_field_id(&c_system, c"out", c"Ljava/io/PrintStream;").unwrap();
        let o_out: Option<LocalRef> = env.get_object_field(&c_system, f_out).unwrap();

        let c_print_stream = env.get_object_class(o_out.as_ref().unwrap());
        let m_println: MethodID<false> = env
            .get_method_id(&c_print_stream, c"println", c"(Ljava/lang/String;)V")
            .unwrap();

        let s_hello = env.new_string("Hello, World!");
        env.call_void_method(o_out.as_ref().unwrap(), m_println, [Arg::from(&s_hello)])
            .unwrap();
    }
}

Features

  • alloc: Enables the use of alloc crate for dynamic memory allocation. (default)
  • print-throwable: Enables the printing of throwable objects.
Commit count: 54

cargo fmt