Claude Cursor Skill

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.

LLM Mart · 0 points · 0 views 0 listing impressions 0 install-command copies
Virus-scanned Reviewed automatically before listing.

Full trust report

Download goldziher-ai-rulez-internal_builtins_bindings_jni-rs_skills_jni-rs-bindings-ca967ad.zip · 0 KB
Part of goldziher/ai-rulez — 151 skills

Install

skills CLI npx skills add https://github.com/Goldziher/ai-rulez/tree/main/internal/builtins/bindings/jni-rs/skills/jni-rs-bindings
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install goldziher-ai-rulez@llmmart
Git git clone https://github.com/Goldziher/ai-rulez.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole goldziher/ai-rulez collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

  • 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.
Files (ai-rulez)
  • SKILL.md 1.4 KB
    ---
    name: jni-rs-bindings
    description: "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.
    

Comments (0)

Sign in to join the conversation.

No comments yet.

Reviews (0)

No reviews yet.

Related