I want to call some java packages from Rust with j4rs crate.
I download all the dependent jars and load them with JVM::deploy_artifact.
After I build the project with cargo build
, I can directly run the binary without any error.
But when I run the project with cargo run
, I will get the following error from java.
Exception in thread "main" java.lang.NoClassDefFoundError: org/astonbitecode/j4rs/api/instantiation/NativeInstantiationImpl
Caused by: java.lang.ClassNotFoundException: org.astonbitecode.j4rs.api.instantiation.NativeInstantiationImpl
at java.net.URLClassLoader.findClass(URLClassLoader.java:407)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
thread 'main' panicked at 'Jvm should be initiated: JavaError("An Exception was thrown by Java while creating global ref... Please check the logs or the console.")', src\main.rs:29:18
Does anybody know why?