{"id":13437847,"url":"https://github.com/benanders/rjni","last_synced_at":"2025-12-27T10:48:10.314Z","repository":{"id":24204932,"uuid":"27596452","full_name":"benanders/rjni","owner":"benanders","description":"Run Java code from Rust!","archived":false,"fork":false,"pushed_at":"2016-12-19T19:15:09.000Z","size":57,"stargazers_count":73,"open_issues_count":4,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-27T23:23:38.430Z","etag":null,"topics":["java","java-native-interface","jvm","rust"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benanders.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-05T15:06:59.000Z","updated_at":"2024-08-25T11:50:50.000Z","dependencies_parsed_at":"2022-08-22T05:00:37.787Z","dependency_job_id":null,"html_url":"https://github.com/benanders/rjni","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benanders%2Frjni","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benanders%2Frjni/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benanders%2Frjni/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benanders%2Frjni/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benanders","download_url":"https://codeload.github.com/benanders/rjni/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244483132,"owners_count":20460063,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","java-native-interface","jvm","rust"],"created_at":"2024-07-31T03:01:00.665Z","updated_at":"2025-12-27T10:48:10.242Z","avatar_url":"https://github.com/benanders.png","language":"Rust","readme":"\nJava Native Interface Bindings for Rust\n=======================================\n\nThis library provides complete FFI bindings to the Java Native Interface, as\nwell as a safe and intuitive wrapper around most these bindings (lacking array\nsupport for now).\n\nFeatures include:\n\n* Creating and configuring an instance of a Java Virtual Machine\n* Loading classes\n* Calling static methods on classes\n* Setting and retrieving public static fields on classes\n* Instantiating objects from a class\n* Calling methods on objects\n* Setting and retrieving public fields on objects\n* Using all primitive Java types and other Java objects as arguments and\n  return values (no support for arrays yet)\n\n\n### Documentation\n\nDocumentation can be found [here](https://benanderson.io/docs/rjni).\n\n\n### Usage\n\nFirst you'll need to compile your Java source code, either as separate `.class`\nfiles, or package them together as a `.jar` archive.\n\nYou need to make sure you target the Java compiler to the JVM version you plan\nto use. This is done through the `-target` and `-source` command line arguments\nto `javac`.\n\nFor example, if you have a `/path/to/project/com/me/Test.java` file (ie. the\nclass `com.me.Test`) and you intend to target the 1.6 JVM:\n\n```bash\n$ javac -target 1.6 -source 1.6 /path/to/project/com/me/Test.java\n```\n\nThis will create a `/path/to/project/com/me/Test.class` file.\n\nThen when you create the JVM in Rust, you need to add `/path/to/project` (ie.\nthe directory containing the root of your Java code) to the classpath, and\nspecify the correct JVM version:\n\n```rust\nuse rjni::{Jvm, Version, Classpath, Options};\n\nfn main() {\n\t// Create a custom classpath, pointing to the directory containing the root\n\t// of your Java code\n\tlet mut classpath = Classpath::new();\n\tclasspath.add(\u0026Path::new(\"/path/to/project\"));\n\n\t// Create a series of configuration options for the JVM, specifying the\n\t// version of the JVM we want to use (1.6), and our custom classpath\n\tlet mut options = Options::new();\n\toptions.version(Version::V16);\n\toptions.classpath(classpath);\n\n\t// Create the JVM with these options\n\tlet jvm = Jvm::new(options).unwrap();\n\n\t// Get the `com.me.Test` class using the JVM\n\tlet class = jvm.class(\"com/me/Test\").unwrap();\n\n\t// ...\n}\n```\n\nSee the `examples` folder for more example code on how to call static methods\non classes, instantiate objects, call methods on objects, and access object\nfields.\n","funding_links":[],"categories":["Development tools","开发工具 Development tools","开发工具"],"sub_categories":["FFI","FFI FFI","示例 FFI"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenanders%2Frjni","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenanders%2Frjni","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenanders%2Frjni/lists"}