海康JAVA SDK初始化路径默认是放在classes下面,见下:
HCNetSDK INSTANCE = (HCNetSDK) Native.loadLibrary("HCNetSDK", HCNetSDK.class);
有时我们为了更加规范,不一定直接放在这个下面,而是放到某个目录中。
我这边就是放到classes下面的hikvision目录中。
改造加载路径,动态获得一个绝对路径来加载库,见下:
import java.io.UnsupportedEncodingException; public class HCNetSDKPath { public static String DLL_PATH; static { String path = (HCNetSDKPath.class.getResource("/").getPath()).replaceAll("%20", " ").substring(1).replace("/", "\"); try { DLL_PATH = java.net.URLDecoder.decode(path, "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } }
HCNetSDK INSTANCE = (HCNetSDK) Native .loadLibrary(HCNetSDKPath.DLL_PATH + "hikvision" + File.separator + "HCNetSDK.dll", HCNetSDK.class);