目录
1.问题现象:
2.问题定位
3.问题解决
4.很少遇到JDK小版本导致出问题
1.问题现象:
使用langchain
<!-- langchain4j start-->
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j</artifactId>
<version>${langchain4j.version}</version>
</dependency>
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-open-ai-spring-boot-starter</artifactId>
<version>${langchain4j.version}</version>
</dependency>
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-embeddings-all-minilm-l6-v2</artifactId>
<version>${langchain4j.version}</version>
</dependency>
java.lang.UnsatisfiedLinkError: no onnxruntime4j_jni in java.library.path
找不到
onnxruntime4j_jni.dll
onnxruntime.dll
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [dev.langchain4j.model.embedding.EmbeddingModel]: Factory method 'embeddingModel' threw exception; nested exception is java.lang.UnsatisfiedLinkError: no onnxruntime4j_jni in java.library.path
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
... 162 more
Caused by: java.lang.UnsatisfiedLinkError: no onnxruntime4j_jni in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at ai.onnxruntime.OnnxRuntime.load(OnnxRuntime.java:371)
at ai.onnxruntime.OnnxRuntime.init(OnnxRuntime.java:157)
at ai.onnxruntime.OrtEnvironment.<clinit>(OrtEnvironment.java:33)
at dev.langchain4j.model.embedding.OnnxBertBiEncoder.<init>(OnnxBertBiEncoder.java:38)
at dev.langchain4j.model.embedding.AbstractInProcessEmbeddingModel.loadFromJar(AbstractInProcessEmbeddingModel.java:21)
at dev.langchain4j.model.embedding.AllMiniLmL6V2EmbeddingModel.<clinit>(AllMiniLmL6V2EmbeddingModel.java:18)
at cn.creditease.rc.server.ai.config.AiConfig.embeddingModel(AiConfig.java:152)
at cn.creditease.rc.server.ai.config.AiConfig$$EnhancerBySpringCGLIB$$7bb97881.CGLIB$embeddingModel$5(<generated>)
at cn.creditease.rc.server.ai.config.AiConfig$$EnhancerBySpringCGLIB$$7bb97881$$FastClassBySpringCGLIB$$416da1b3.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at cn.creditease.rc.server.ai.config.AiConfig$$EnhancerBySpringCGLIB$$7bb97881.embeddingModel(<generated>)
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.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 163 more
都是jdk1.8同样的windows别的同事电脑没问题。
2.问题定位
看日志错误代码在
AllMiniLmL6V2EmbeddingModel.class
private static final OnnxBertBiEncoder MODEL = loadFromJar(
"all-minilm-l6-v2.onnx",
"bert-vocabulary-en.txt",
PoolingMode.MEAN
);
AbstractInProcessEmbeddingModel.class
static OnnxBertBiEncoder loadFromJar(String modelFileName, String vocabularyFileName, PoolingMode poolingMode) {
InputStream inputStream = AbstractInProcessEmbeddingModel.class.getResourceAsStream("/" + modelFileName);
return new OnnxBertBiEncoder(
inputStream,
AbstractInProcessEmbeddingModel.class.getResource("/" + vocabularyFileName),
poolingMode
);
}
加载的 user_paths路径 也没看到对应文件
换个思路处理:由于别的1.8同事执行没问题,所以去官网下载最终版本的 jdk1.8
Java Downloads | Oracle
更换jdk后 正常执行,
重新debug看问题,
OnnxRuntime.java
ai.onnxruntime.OnnxRuntime#extractFromResources
两个版本之间的区别
jdk 1.8.0_401
C:\Users\Administrator\AppData\Local\Temp\onnxruntime-java*\
onnxruntime4j_jni.dll
onnxruntime.dll
jdk 1.8.0_114
C:\Users\Administrator\AppData\Local\Temp\onnxruntime-java*\
空
3.问题解决
原有 jdk 1.8.0_114 升级为 jdk 1.8.0_401
原因
两个版本之间的区别
jdk 1.8.0_401
C:\Users\Administrator\AppData\Local\Temp\onnxruntime-java*\
onnxruntime4j_jni.dll
onnxruntime.dll
jdk 1.8.0_114
C:\Users\Administrator\AppData\Local\Temp\onnxruntime-java*\
空
4.很少遇到JDK小版本导致出问题
Java Downloads | Oracle