I am trying to emulate the test cases at https://github.com/jni-rs/jni-rs/blob/master/tests/jni_api.rs and https://github.com/jni-rs/jni-rs/blob/master/tests/util/mod.rs . I have created a project with main.rs
use jni::{InitArgsBuilder, JNIVersion, JavaVM};
fn main() {
let jvm_args = InitArgsBuilder::new()
.version(JNIVersion::V8)
.option("-Xcheck:jni")
//.option(format!("-Djava.class.path={}", heinous_classpath()))
.build()
.unwrap_or_else(|e| panic!("{}", e.display_chain().to_string()));
let jvm = JavaVM::new(jvm_args);
}
and Cargo.toml:
[package]
name = "rust_call_jni"
version = "0.1.0"
authors = ["Robert Forsman <git@thoth.purplefrog.com>"]
edition = "2018"
[dependencies]
jni = "0.12.3"
When I do a cargo build
I get the following error:
error[E0432]: unresolved import `jni::InitArgsBuilder`
--> src/main.rs:1:11
|
1 | use jni::{InitArgsBuilder, JNIVersion, JavaVM};
| ^^^^^^^^^^^^^^^ no `InitArgsBuilder` in the root
error[E0599]: no function or associated item named `new` found for type `jni::wrapper::java_vm::vm::JavaVM` in the current scope
--> src/main.rs:12:23
|
12 | let jvm = JavaVM::new(jvm_args);
| --------^^^
| |
| function or associated item not found in `jni::wrapper::java_vm::vm::JavaVM`
I'm using Rust 1.34.2.
How can I modify my source code to properly import and invoke the constructors?
Based on the pointer from Svetlin Zarev, I was able to rummage around in the documentation and figure out the proper syntax to enable the invocation feature.
The most important thing was a modification to Cargo.toml. The docstring for the jni crate might benefit from including this clause for folks with less experience writing Cargo.toml:
I had to modify main.rs to fix some errors that were masked by the earlier errors:
It turns out there is another Cargo.toml syntax for dependencies with multiple attributes I discovered later on: