海康sdk Windows,linux双系统配置
项目目录:
linux系统配置
/src/main/resources/linux-lib文件夹下的文件放到linux /usr/local/linux-lib 路径配置
public static final String PATH_LINUXS ="/usr/local/linux-lib/libhcnetsdk.so";
windows系统路径配置
public static final String PATH_WINS = System.getProperty("user.dir").concat("\\core\\src\\main\\resources\\windows-lib\\HCNetSDK.dll");
HKNetSDKPath文件:
package com.***.sdk;
import lombok.extern.slf4j.Slf4j;
public final class HKNetSDKPath {
public static final String PATH_WINS = System.getProperty("user.dir").concat("\\core\\src\\main\\resources\\windows-lib\\HCNetSDK.dll");
public static final String PATH_LINUXS ="/usr/local/linux-lib/libhcnetsdk.so";
}
HKNetSDK文件:
使用方法:
if (Platform.isWindows()) {
hCNetSDK = (HCNetSDK) Native.loadLibrary(HKNetSDKPath.PATH_WINS, HCNetSDK.class);
}
if (Platform.isLinux()) {
hCNetSDK = (HCNetSDK) Native.loadLibrary(HKNetSDKPath.PATH_LINUXS, HCNetSDK.class);
}
一般长连接报错,很多时候是sdk版本的问题,官方下载地址:海康官网下载 linux lib在lib目录下,windows在库文件下。 网上文档较少,资料收集不易,如果有帮助点赞支持一下。
常见错误:
defence-service_1 | 2022-04-06 17:04:08.892 ERROR 1 --- [nio-8666-exec-1] .h.b.c.s.m
.AppExceptionHandlerController : 服务器发生错误: Handler dispatch failed; nested excepti
on is java.lang.UnsatisfiedLinkError: Unable to load library '/usr/local/linux-
lib/libhcnetsdk.so': /usr/local/linux-lib/libhcnetsdk.so: cannot open shared object fi
le: No such file or directory
解决方法: 一般是路径错误,或者在路径处为搜索到包。
|