-
Notifications
You must be signed in to change notification settings - Fork 42
Closed
Description
Thanks for creating j4rs, it's a very nice crate to use. I am trying to use j4rs in tests, to compare the output of rust library with an existing java library. However, usually this fails in CI, and it looks like the artifacts aren't downloaded: https://github.com/seanyoung/cir/actions/runs/3824139027/jobs/6506015468
Here is a simple reproduction.
use itertools::Itertools;
use j4rs::{Instance, InvocationArg, JavaClass, Jvm, JvmBuilder, MavenArtifact};
use std::collections::HashMap;
fn main() {
let jvm = JvmBuilder::new().build().unwrap();
let dbx_artifact = MavenArtifact::from("org.harctoolbox:IrpTransmogrifier:1.2.11");
jvm.deploy_artifact(&dbx_artifact).unwrap();
let dbx_artifact = MavenArtifact::from("org.antlr:antlr4:4.9.3");
jvm.deploy_artifact(&dbx_artifact).unwrap();
let dbx_artifact = MavenArtifact::from("org.antlr:antlr4-runtime:4.9.3");
jvm.deploy_artifact(&dbx_artifact).unwrap();
let irp = jvm.create_instance(
"java.lang.String",
&[InvocationArg::try_from("{38.4k,564}<1,-1|1,-3>(16,-8,D:8,S:8,F:8,~F:8,1,^108m,(16,-4,1,^108m)*) [D:0..255,S:0..255=255-D,F:0..255]").unwrap()],
).unwrap();
let protocol = jvm
.create_instance("org.harctoolbox.irp.Protocol", &[irp.into()])
.unwrap();
let param = HashMap::from([("D", 15), ("S", 1), ("F", 0xe4)]);
let jparam = jvm
.java_map(JavaClass::String, JavaClass::Long, param)
.unwrap();
let res = jvm
.invoke(&protocol, "toIrSignal", &[jparam.into()])
.unwrap();
let frequency: f64 = jvm
.to_rust(jvm.invoke(&res, "getFrequency", &[]).unwrap())
.unwrap();
let duty_cycle: Option<f64> = jvm
.to_rust(jvm.invoke(&res, "getDutyCycle", &[]).unwrap())
.unwrap();
let intro: Vec<u32> = jvm
.to_rust(jvm.invoke(&res, "getIntroInts", &[]).unwrap())
.unwrap();
let repeat: Vec<u32> = jvm
.to_rust(jvm.invoke(&res, "getRepeatInts", &[]).unwrap())
.unwrap();
let ending: Vec<u32> = jvm
.to_rust(jvm.invoke(&res, "getEndingInts", &[]).unwrap())
.unwrap();
println!("carrier:{}", frequency);
println!("duty_cycle:{:?}", duty_cycle);
println!("intro:{}", intro.iter().join(","));
println!("repeat:{}", repeat.iter().join(","));
println!("ending:{}", ending.iter().join(","));
}If I run this after cargo clean, it intermittently produces:
$ cargo run
Exception in thread "main" org.astonbitecode.j4rs.errors.InstantiationException: Cannot create instance of org.harctoolbox.irp.Protocol
at org.astonbitecode.j4rs.api.instantiation.NativeInstantiationImpl.instantiate(NativeInstantiationImpl.java:47)
Caused by: java.lang.ClassNotFoundException: org.harctoolbox.irp.Protocol
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:375)
at org.astonbitecode.j4rs.utils.Utils.forNameEnhanced(Utils.java:43)
at org.astonbitecode.j4rs.api.instantiation.NativeInstantiationImpl.createInstance(NativeInstantiationImpl.java:92)
at org.astonbitecode.j4rs.api.instantiation.NativeInstantiationImpl.instantiate(NativeInstantiationImpl.java:44)
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: JavaError("An Exception was thrown by Java... Please check the logs or the console.")', src/main.rs:21:10
If there is anything I can do to help, please let me know.
Metadata
Metadata
Assignees
Labels
No labels