j4rs
j4rs copied to clipboard
use a java library?
Hello Team,
I have a java library to use, code will be like this: https://github.com/dynatrace-research/exaloglog-paper/blob/main/java/src/test/java/com/dynatrace/exaloglogpaper/DistinctCountUtilTest.java
How can I use it in j4rs?
Thanks, Jianshu
You should just create the Jvm
specifying the class you want to include in the classpath.
For example, if you have the Java class:
package org.my;
public class Test {
public void greet(String name) {
System.out.println("Hello " + name);
}
}
in a directory /some/location/classes
, you can invoke the method greet
like:
let jvm: Jvm = JvmBuilder::new().classpath_entry(ClasspathEntry::new("/some/location/classes")).build()?;
let test_instance = jvm.create_instance("org.my.Test", &[])?;
let name = InvocationArg::try_from("Chester")?;
let _ = jvm.invoke(&test_instance, "greet", &[name])?;
It's been some time since this is inactive. Closing...