j4rs icon indicating copy to clipboard operation
j4rs copied to clipboard

Con't initialize jvm

Open Swibon96 opened this issue 1 year ago • 3 comments

when i initialize a jvm, like this:
let entry = ClasspathEntry::new("/workspace/code/zenoh-flow-java/zenoh-flow/out/artifacts/zenoh_flow_jar/zenoh-flow.jar");

    let ja = JvmBuilder::new()
        .with_default_classloader() 
        .classpath_entry(entry)
        .build()
        .unwrap();

I got this panick: thread '' panicked at 'called Result::unwrap() on an Err value: GeneralError("Error { kind: NotFound, message: "No such file or directory (os error 2)" }")',

Swibon96 avatar Feb 02 '24 05:02 Swibon96

I cannot say what throws this error. However, I can say that if a ClasspathEntry is not found, or is not a valid path, the Jvm is created without issues. It is just that the jar specified is not in the classpath and therefore, when you need it later, you will get a Exception from Java like:

Exception in thread "main" org.astonbitecode.j4rs.errors.InstantiationException: Cannot create instance of blah.blah.Blah at org.astonbitecode.j4rs.api.instantiation.NativeInstantiationImpl.instantiate(NativeInstantiationImpl.java:47) Caused by: java.lang.ClassNotFoundException: blah.blah.Blah 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:525) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Class.java:467) at org.astonbitecode.j4rs.utils.Utils.forNameEnhanced(Utils.java:56) at org.astonbitecode.j4rs.api.instantiation.NativeInstantiationImpl.createInstance(NativeInstantiationImpl.java:96) at org.astonbitecode.j4rs.api.instantiation.NativeInstantiationImpl.instantiate(NativeInstantiationImpl.java:44)

Please give more details, running j4rs with debug logging enabled.

astonbitecode avatar Feb 02 '24 06:02 astonbitecode

when i export " J4RS_CONSOLE_LOG_LEVEL=debug", it seems not work. I guess it has something to do with the JAVA_HOME environment variable? Or the libjvm.so file. Can you tell me how JVM gets these files?

Swibon96 avatar Feb 04 '24 02:02 Swibon96

when i export " J4RS_CONSOLE_LOG_LEVEL=debug", it seems not work.

Do you mean that debugging did not work? I asked to add the property in order to have more logging and maybe see what happens. Can you please provide these logs? Without it, there is not much we can do.

If JAVA_HOME is not correctly set, j4rs cannot locate the JVM and you may have this error.

astonbitecode avatar Feb 05 '24 07:02 astonbitecode

It's been some time since this is inactive. Closing...

astonbitecode avatar Apr 10 '24 13:04 astonbitecode