- Use
jnicrate for Rust-Java/JVM interop. Functions must be#[no_mangle] pub extern "system". - Follow JNI naming:
Java_com_example_ClassName_methodName. Match Java native method signatures exactly. - Use
JNIEnvfor all JNI operations. Access Java types viaJObject,JString,JClasswrappers. - String conversion:
env.get_string(&jstring)to read,env.new_string("value")to create. - Error handling: check
env.exception_check()after JNI calls. Throw Java exceptions viaenv.throw_new(). - Global references (
env.new_global_ref()) for objects accessed across threads or native calls. - Build with
cargo build --releaseto produce shared library. Load in Java withSystem.loadLibrary(). - Test Java side with JUnit, Rust core logic with standard
#[test]. Integration tests via JNI calls. - Keep JNI layer thin — business logic in Rust, Java provides API surface.
- Memory: JNI local references are auto-freed on native return. Use
env.delete_local_ref()in loops. - Anti-patterns: holding JNI references across threads without global refs, ignoring exception checks,
unwrap()in JNI functions.
Jni Rs Bindings
jni-rs conventions for exposing a Rust core to Java/JVM: JNI export naming, JNIEnv usage, string conversion, exception checks/throws, global references, and library loading. Load when generating or reviewing jni-rs Java/JVM bindings for a Rust library.
Jni Rs Bindings by goldziher · 9b8b52e
npx skillmds@latest add goldziher/jni-rs-bindings File contents
---name: jni-rs-bindingsdescription: jni-rs conventions for exposing a Rust core to Java/JVM: JNI export naming, JNIEnv usage, string conversion, exception checks/throws, global references, and library loading. Load when generating or reviewing jni-rs Java/JVM bindings for a Rust library.---- Use `jni` crate for Rust-Java/JVM interop. Functions must be `#[no_mangle] pub extern "system"`.- Follow JNI naming: `Java_com_example_ClassName_methodName`. Match Java native method signatures exactly.- Use `JNIEnv` for all JNI operations. Access Java types via `JObject`, `JString`, `JClass` wrappers.- String conversion: `env.get_string(&jstring)` to read, `env.new_string("value")` to create.- Error handling: check `env.exception_check()` after JNI calls. Throw Java exceptions via `env.throw_new()`.- Global references (`env.new_global_ref()`) for objects accessed across threads or native calls.- Build with `cargo build --release` to produce shared library. Load in Java with `System.loadLibrary()`.- Test Java side with JUnit, Rust core logic with standard `#[test]`. Integration tests via JNI calls.- Keep JNI layer thin — business logic in Rust, Java provides API surface.- Memory: JNI local references are auto-freed on native return. Use `env.delete_local_ref()` in loops.- Anti-patterns: holding JNI references across threads without global refs, ignoring exception checks, `unwrap()` in JNI functions.
goldziher/ai-rulez/tree/main/internal/builtins/bindings/jni-rs/skills/jni-rs-bindings commit 9b8b52ed34
Frequently asked questions
Run npx skillmds@latest add goldziher/jni-rs-bindings in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
jni-rs conventions for exposing a Rust core to Java/JVM: JNI export naming, JNIEnv usage, string conversion, exception checks/throws, global references, and library loading. Load when generating or reviewing jni-rs Java/JVM bindings for a Rust library. It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
goldziher (@goldziher) published this skill. Their other Agent Skills are listed on their SkillMD profile.