j4rs icon indicating copy to clipboard operation
j4rs copied to clipboard

windows7 sunmscapi.dll: Can't find dependent libraries

Open wfeii1980 opened this issue 1 year ago • 8 comments

env: Windows 7 Home SP1 jre-8u-391 j4rs = "0.17.1"

issue:

java -jar local-server.jar // Using the command line is correct

Using j4rs

        let jvm = match JvmBuilder::new()
            .with_default_classloader()
            .classpath_entry(ClasspathEntry::new(&config.file))
            .java_opts(java_opts)
            .build()
        {
            Ok(v) => v,
            Err(e) => {
                debug!("JvmBuilder {} {:?}", Error::last_os_error(), e);
                return Err(ResultError::from(e));
            }
        };

        match jvm.invoke_static(&config.class, SERVICE_STARTER_CLASS_START, &[]) {
            Ok(v) => {
                let n: i32 = match jvm.to_rust(v) {
                    Ok(v) => v,
                    Err(e) => {
                        return Err(ResultError::from(e));
                    }
                };

                if n != 1 {
                    return Err(ResultError::new(&format!("start return {}", n)));
                }

                // running
                loop {
					...
                }

                if let Err(e) =
                    jvm.invoke_static(&config.class, SERVICE_STARTER_CLASS_SHUTDOWN, &[])
                {
                    return Err(ResultError::from(e));
                }
            }
            Err(e) => {
                return Err(ResultError::from(e));
            }
        };

j4rs log

2024-01-13T09:33:01.566812400+08:00 - INFO Setting classpath to -Djava.class.path=D:\workflow\jassets\j4rs-0.17.1-jar-with-dependencies.jar;D:\workflow\jassets\local-server.jar;local-server.jar
2024-01-13T09:33:01.566812400+08:00 - INFO Setting library path to -Djava.library.path=D:\workflow\deps
2024-01-13T09:33:01.566812400+08:00 - INFO Passing to the Java world the name of the library to load: j4rs-525e7fc775af8d8d
2024-01-13T09:33:01.566812400+08:00 - DEBUG Creating a Jvm
2024-01-13T09:33:01.769612800+08:00 - INFO No JVMs exist. Creating a new one...
2024-01-13T09:33:02.365414+08:00 - DEBUG Called set_jni_get_method_id
2024-01-13T09:33:02.365414+08:00 - DEBUG Called set_jni_get_static_method_id
2024-01-13T09:33:02.365414+08:00 - DEBUG Called set_jni_new_object
2024-01-13T09:33:02.365414+08:00 - DEBUG Called set_jni_new_string_utf
2024-01-13T09:33:02.365414+08:00 - DEBUG Called set_jni_get_string_utf_chars
2024-01-13T09:33:02.365414+08:00 - DEBUG Called set_jni_release_string_utf_chars
2024-01-13T09:33:02.365414+08:00 - DEBUG Called set_jni_call_object_method
2024-01-13T09:33:02.365414+08:00 - DEBUG Called set_jni_call_byte_method
2024-01-13T09:33:02.365414+08:00 - DEBUG Called set_jni_call_short_method
2024-01-13T09:33:02.365414+08:00 - DEBUG Called set_jni_call_int_method
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_jni_call_long_method
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_jni_call_float_method
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_jni_call_double_method
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_jni_call_void_method
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_jni_call_static_object_method
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_jni_new_object_array
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_jni_set_object_array_element
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_jni_exception_check
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_jni_exception_describe
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_jni_exception_clear
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_jni_delete_local_ref
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_jni_delete_global_ref
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_jni_new_global_ref
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_jni_throw_new
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_is_same_object
2024-01-13T09:33:02.381014+08:00 - DEBUG Called set_thread_local_env
2024-01-13T09:33:02.381014+08:00 - DEBUG Initializing NativeCallbackSupport with libname j4rs-525e7fc775af8d8d
2024-01-13T09:33:02.381014+08:00 - DEBUG Invoking static method initialize of class org.astonbitecode.j4rs.api.invocation.NativeCallbackToRustChannelSupport using 1 arguments
2024-01-13T09:33:02.615014400+08:00 - DEBUG Called set_factory_class
2024-01-13T09:33:02.615014400+08:00 - DEBUG Called set_factory_create_for_static_method
2024-01-13T09:33:02.693014600+08:00 - DEBUG Called set_invocation_arg_class
2024-01-13T09:33:02.693014600+08:00 - DEBUG Creating jobject from Rust basic for class java.lang.String
2024-01-13T09:33:02.693014600+08:00 - DEBUG Calling the InvocationArg constructor with 'java.lang.String'
2024-01-13T09:33:02.693014600+08:00 - DEBUG Called set_inv_arg_basic_rust_constructor_method
2024-01-13T09:33:02.693014600+08:00 - DEBUG Called set_java_instance_class
2024-01-13T09:33:02.693014600+08:00 - DEBUG Called set_invoke_static_method
2024-01-13T09:33:02.982216+08:00 - DEBUG Dropping an instance of known_in_java_world
2024-01-13T09:33:02.982216+08:00 - DEBUG Dropping an instance of java.lang.String
2024-01-13T09:33:02.982216+08:00 - DEBUG NativeCallbackSupport initialized
2024-01-13T09:33:02.982216+08:00 - DEBUG Invoking static method start of class ai.restosuite.localserver.ApplicationStarter using 0 arguments
2024-01-13T09:33:07.274223200+08:00 - DEBUG Called set_get_object_class_name_method
2024-01-13T09:33:07.284223300+08:00 - DEBUG Called set_get_object_method
2024-01-13T09:33:07.284223300+08:00 - DEBUG Called set_integer_class
2024-01-13T09:33:07.284223300+08:00 - DEBUG Called set_integer_to_int_method
2024-01-13T09:33:07.284223300+08:00 - DEBUG Dropping an instance of known_in_java_world
2024-01-13T09:33:07.284223300+08:00 - INFO start return 1

jar error log

2024-01-13 09:33:40.584$$$$nioEventLoopGroup-3-1$$ERROR$$$$$$$$$$$$$$$$$$$$$$Failed to process the request, the exception was not handled!: ai.restosuite.curiosity.application.exception.ServerHandlerException: Request throws throwable.
	at ai.restosuite.curiosity.kernel.endpoint.interceptor.EndpointInterceptorChain.applyPreAndPostHandle(EndpointInterceptorChain.java:74)
	at ai.restosuite.curiosity.kernel.endpoint.handler.HttpRequestHandler$1.handle(HttpRequestHandler.java:129)
	at ai.restosuite.curiosity.kernel.endpoint.handler.HttpRequestHandler$1.handle(HttpRequestHandler.java:126)
	at ai.restosuite.curiosity.kernel.concurrency.CuriosityContextSwitcher$CuriosityContextCallable.call(CuriosityContextSwitcher.java:36)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsatisfiedLinkError: C:\Program Files\Java\jre-1.8\bin\sunmscapi.dll: Can't find dependent libraries
	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	at java.lang.ClassLoader.loadLibrary0(Unknown Source)
	at java.lang.ClassLoader.loadLibrary(Unknown Source)
	at java.lang.Runtime.loadLibrary0(Unknown Source)
	at java.lang.System.loadLibrary(Unknown Source)
	at sun.security.mscapi.SunMSCAPI$1.run(SunMSCAPI.java:52)
	at sun.security.mscapi.SunMSCAPI$1.run(SunMSCAPI.java:50)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.security.mscapi.SunMSCAPI.<clinit>(SunMSCAPI.java:50)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at sun.security.jca.ProviderConfig$2.run(Unknown Source)
	at sun.security.jca.ProviderConfig$2.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.security.jca.ProviderConfig.doLoadProvider(Unknown Source)
	at sun.security.jca.ProviderConfig.getProvider(Unknown Source)
	at sun.security.jca.ProviderList.loadAll(Unknown Source)
	at sun.security.jca.ProviderList.removeInvalid(Unknown Source)
	at sun.security.jca.Providers.getFullProviderList(Unknown Source)
	at java.security.Security.getProviders(Unknown Source)
	at okhttp3.internal.platform.Platform.isConscryptPreferred(Platform.java:195)
	at okhttp3.internal.platform.Platform.findJvmPlatform(Platform.java:215)
	at okhttp3.internal.platform.Platform.findPlatform(Platform.java:204)
	at okhttp3.internal.platform.Platform.<clinit>(Platform.java:78)
	at okhttp3.OkHttpClient.newSslSocketFactory(OkHttpClient.java:292)
	at okhttp3.OkHttpClient.<init>(OkHttpClient.java:258)
	at okhttp3.OkHttpClient.<init>(OkHttpClient.java:231)
	at ai.restosuite.localserver.common.http.HttpClientManager.createHttpClient(HttpClientManager.java:47)
	at ai.restosuite.localserver.common.http.HttpClientManager.getInstance(HttpClientManager.java:25)
	at ai.restosuite.localserver.common.http.HttpClientHelper.post(HttpClientHelper.java:52)
	at ai.restosuite.localserver.common.http.HttpClientHelper.post(HttpClientHelper.java:24)
	at ai.restosuite.localserver.shop.infra.org.ActiveShopGatewayImpl.activateShop(ActiveShopGatewayImpl.java:57)
	at ai.restosuite.localserver.app.shop.executor.ActivateShopCmdExe.activateShop(ActivateShopCmdExe.java:24)
	at ai.restosuite.localserver.app.shop.service.ActivateShopService.activateShop(ActivateShopService.java:62)
	at ai.restosuite.localserver.app.shop.endpoint.ShopBaseEndpoint.activateShop(ShopBaseEndpoint.java:90)
	at ai.restosuite.localserver.app.shop.endpoint.ShopBaseEndpoint_ActivateShop.handleRequest(ShopBaseEndpoint_ActivateShop.java:38)
	at ai.restosuite.curiosity.kernel.endpoint.handler.HttpRequestHandler.processingBusiness(HttpRequestHandler.java:165)
	at ai.restosuite.curiosity.kernel.endpoint.interceptor.EndpointInterceptorChain.applyPreAndPostHandle(EndpointInterceptorChain.java:70)
	... 7 more

On Windows 10 does not have this issue.

Has anyone encountered the same problem before?

wfeii1980 avatar Jan 13 '24 02:01 wfeii1980

The Rust logs do not indicate any issue with starting JVM...

As a first question, are you sure that the dll exists in the expected path: "C:\Program Files\Java\jre-1.8\bin\sunmscapi.dll"?

In case it exists, I see that the -Djava.library.path=D:\workflow\deps is set. Have you tried adding C:\Program Files\Java\jre-1.8\bin to the java_opts once you are building the Jvm? Something like:

JvmBuilder::new()
            .with_default_classloader()
            .classpath_entry(ClasspathEntry::new(&config.file))
            .java_opts(java_opts)
            // Try adding the next two calls
            .with_no_implicit_classpath()
            .java_opt(JavaOpt::new(
                "-Djava.library.path=D:\workflow\deps\;C:\Program Files\Java\jre-1.8\bin\",
            ))
            .build()

astonbitecode avatar Jan 22 '24 10:01 astonbitecode

The Rust logs do not indicate any issue with starting JVM...

As a first question, are you sure that the dll exists in the expected path: "C:\Program Files\Java\jre-1.8\bin\sunmscapi.dll"?

In case it exists, I see that the -Djava.library.path=D:\workflow\deps is set. Have you tried adding C:\Program Files\Java\jre-1.8\bin to the java_opts once you are building the Jvm? Something like:

JvmBuilder::new()
            .with_default_classloader()
            .classpath_entry(ClasspathEntry::new(&config.file))
            .java_opts(java_opts)
            // Try adding the next two calls
            .with_no_implicit_classpath()
            .java_opt(JavaOpt::new(
                "-Djava.library.path=D:\workflow\deps\;C:\Program Files\Java\jre-1.8\bin\",
            ))
            .build()

C:\Program Files\Java\jre-1.8\bin\sunmscapi.dll File exists。Use Dependency Walker to check is indeed a red warning。

add '-Djava.library.path' Not successful either

INFO Setting classpath to -Djava.class.path=D:\workflow\jassets\j4rs-0.17.1-jar-with-dependencies.jar;D:\workflow\jassets\local-server.jar;local-server.jar
INFO Setting library path to -Djava.library.path=D:\workflow\deps;C:\Windows\System32;C:\Program Files\Java\jre-1.8\bin
INFO Passing to the Java world the name of the library to load: j4rs-8e4bd405dcba71b6
INFO No JVMs exist. Creating a new one...
ERROR exit {"error":"An Exception was thrown by Java... Please check the logs or the console."}

wfeii1980 avatar Jan 22 '24 10:01 wfeii1980

This time there is an error in the creation of the JVM.

What is it? Can you check in the console?

astonbitecode avatar Jan 22 '24 10:01 astonbitecode

Perhaps some new issues are interfering with this test, I will try again.

wfeii1980 avatar Jan 23 '24 07:01 wfeii1980

Hi: astonbitecode!

No problem solved!

Calling with_no_implicit_classpath() will affect -Djava.class.path,I directly modified the function java_library_path() for testing。

2024-01-23 17-07-33屏幕截图

I have set the path according to the configuration of the java.exe -jar my.jar package, but the issue remains the same as before.

I think java.exe must have done something, but we don't know!

wfeii1980 avatar Jan 23 '24 09:01 wfeii1980

2024-01-23 18-13-06屏幕截图

wfeii1980 avatar Jan 23 '24 10:01 wfeii1980

Can you please provide a translation for: image

astonbitecode avatar Jan 23 '24 10:01 astonbitecode

Ok used an OCR tool and saw "Error opening file. The system could not find the specified file".

Could it be a permissions issue?

astonbitecode avatar Jan 23 '24 12:01 astonbitecode

Any news for this? It doesn't seem a j4rs issue, was it?

astonbitecode avatar Mar 15 '24 07:03 astonbitecode