【发布时间】:2019-07-22 21:51:36
【问题描述】:
我正在尝试模拟 https://github.com/jni-rs/jni-rs/blob/master/tests/jni_api.rs 和 https://github.com/jni-rs/jni-rs/blob/master/tests/util/mod.rs 的测试用例。我用 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);
}
和 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"
当我执行cargo build 时,我收到以下错误:
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`
我正在使用 Rust 1.34.2。
如何修改我的源代码以正确导入和调用构造函数?
【问题讨论】:
-
它无法编译,因为它需要
#[cfg(feature = "invocation")],但我找不到此功能的含义。很可能它不在稳定频道上。
标签: rust