diff --git a/pqs-advance/advance-boot/src/main/java/com/njcn/advance/utils/JnaCallDllOrSo.java b/pqs-advance/advance-boot/src/main/java/com/njcn/advance/utils/JnaCallDllOrSo.java index 7d4fd7950..56677c852 100644 --- a/pqs-advance/advance-boot/src/main/java/com/njcn/advance/utils/JnaCallDllOrSo.java +++ b/pqs-advance/advance-boot/src/main/java/com/njcn/advance/utils/JnaCallDllOrSo.java @@ -20,21 +20,20 @@ public class JnaCallDllOrSo { public JnaCallDllOrSo(String name) { super(); - String suffix = ".dll"; try { String os = System.getProperty("os.name"); - // windows操作系统为1 否则为0 int beginIndex = os != null && os.startsWith("Windows") ? 1 : 0; String nameDll; if (beginIndex == 0) { - //linux操作系统 - nameDll = "lib" + name + "_dll"; - suffix = ".so"; + nameDll = "lib" + name + ".so"; } else { nameDll = name; + if (!name.endsWith(".dll")) { + nameDll = name + ".dll"; + } } - String tem = "/usr/local/dllFile/"+ nameDll.concat(suffix); + String tem = "/usr/local/dllFile/"+ nameDll; File dockerFile = new File(tem); if(!dockerFile.exists()){ boolean f = dockerFile.getParentFile().mkdirs(); @@ -42,7 +41,11 @@ public class JnaCallDllOrSo { System.out.println("文件夹创建:"+f); System.out.println("文件创建:"+d); - try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(nameDll.concat(suffix))) { + try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(nameDll)) { + if (inputStream == null) { + log.error("找不到资源文件: {}", nameDll); + throw new FileNotFoundException("找不到资源文件: " + nameDll); + } try (FileOutputStream outputStream = new FileOutputStream(dockerFile)) { byte[] buffer = new byte[1024]; int bytesRead; @@ -53,9 +56,11 @@ public class JnaCallDllOrSo { } } this.path = dockerFile.getAbsolutePath(); + System.out.println("动态库路径: " + this.path); } catch (Exception e) { log.error("调用高级算法文件异常,异常信息如下:"); - log.error(e.getMessage()); + log.error(e.getMessage(), e); + throw new RuntimeException("加载动态库失败: " + e.getMessage(), e); }