gpt4 book ai didi

java - Spring Boot - .dll 已加载到具有两个项目的另一个类加载器中

转载 作者:行者123 更新时间:2023-12-03 21:24:06 26 4
gpt4 key购买 nike

我创建了两个 Spring Boot 项目。
一个是 test项目和另一个是我的 working项目

测试项目:

使用 System.load 我将 .dll 加载到目录
.dll 位于文件夹 test 项目中

工作项目:

现在我正在尝试加载相同的 .dll
.dll 放在我的工作文件夹中

所以每个项目都有自己的 .dll

我总是出错:

java.lang.UnsatisfiedLinkError dir already loaded in another classloader



我是否必须从测试项目中“卸载”第一个 .dll?

tomcat 是否有任何位置为我的测试项目 session 加载 .dll 以便我无法为我的工作项目再次加载 .dll?

或者

如何加载“已加载”库?
Exception in thread "restartedMain" java.lang.UnsatisfiedLinkError: Native Library C:\Dev\workspace\lightserver\src\main\libs\huesdk.dll already loaded in another classloader
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1907)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)

最佳答案

spring中集成外部dll时出现,抛出java.lang.UnsatisfiedLinkError异常:

Exception in thread "restartedMain" java.lang.UnsatisfiedLinkError: Native Library *\opencv_java400.dll already loaded in another classloader
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1907)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at com.jinbill.ocr.OcrApplication.<clinit>(OcrApplication.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:15)
使用spring-boot-devtools,springboot会在运行过程中重新加载上下文(启动时会重新加载一次),所以会提示加载链接库,直接在加载的动态链接库所在的位置加上try catch就可以了线:
@SpringBootApplication
public class AppApplication {
static {
try {
System.loadLibrary(NATIVE_LIBRARY_NAME);
} catch (UnsatisfiedLinkError ignore) {
/ / After using spring-dev-tools, the context will be loaded multiple times, so here will throw the exception that the link library has been loaded.
/ / If there is this exception, the link library has been loaded, you can directly swallow the exception.
}
}

public static void main(String[] args) {
SpringApplication.run(AppApplication.class, args);
}
}

关于java - Spring Boot - .dll 已加载到具有两个项目的另一个类加载器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49629917/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com