Native.loadLibrary Caused by: java.lang.UnsatisfiedLinkError: Unable to load library

JAVA Native加载dll库,把库路径换成绝对路径还是出现下面的问题

Caused by: java.lang.UnsatisfiedLinkError: Unable to load library XXX

找了半天原因,原来是绝对路径的分隔符有问题。

String classpath = Thread.currentThread().getContextClassLoader().getResource("/").getPath();

这样获取的路径在windows操作系统下面分隔符是/,需要替换成“\”

需要做如下处理:

String path = classpath.substring(1,classpath.indexOf("classes")).replace("/", File.separator)+"lib"+File.separator+"hcnetsdk"+File.separator+"HCNetSDK";


hCNetSDK = (HCNetSDK) Native.loadLibrary(path, HCNetSDK.class);


你可能感兴趣的:(Native.loadLibrary Caused by: java.lang.UnsatisfiedLinkError: Unable to load library)