From a8f2f4e6f1a9173d7eb9779c7879674015c8cda0 Mon Sep 17 00:00:00 2001 From: dengzedong <dengzedong@email> Date: 星期四, 10 十月 2024 14:07:31 +0800 Subject: [PATCH] 项目启动加载已发布的dll和jar 先判断文件是否存在 --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/DllUtils.java | 33 ++++++++++++++++++--------------- 1 files changed, 18 insertions(+), 15 deletions(-) diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/DllUtils.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/DllUtils.java index 94b3964..61cb7a8 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/DllUtils.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/common/utils/DllUtils.java @@ -1,5 +1,6 @@ package com.iailab.module.model.mpk.common.utils; +import cn.hutool.core.io.FileUtil; import com.iailab.module.model.mpk.common.MdkConstant; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -181,23 +182,25 @@ String jarFilePath = bakPath + File.separator + projectId + MdkConstant.SPLIT + historyId + ".jar"; String dllFilePath = bakPath + File.separator + projectId + MdkConstant.SPLIT + historyId + ".dll"; - URLClassLoader urlClassLoader = null; - try { - // 加载新的jar - urlClassLoader = DllUtils.loadJar(jarFilePath); - } catch (Exception e) { - throw new RuntimeException("加载jar异常",e); - } + if (FileUtil.exist(jarFilePath) && FileUtil.exist(dllFilePath)) { + URLClassLoader urlClassLoader = null; + try { + // 加载新的jar + urlClassLoader = loadJar(jarFilePath); + } catch (Exception e) { + throw new RuntimeException("加载jar异常",e); + } - try { - // 加载新的dll - DllUtils.loadDll(urlClassLoader.loadClass("iail.mdk.model.common.Environment"),dllFilePath); - } catch (Exception e) { - DllUtils.unloadJar(urlClassLoader); - throw new RuntimeException("加载dll异常",e); + try { + // 加载新的dll + loadDll(urlClassLoader.loadClass("iail.mdk.model.common.Environment"),dllFilePath); + } catch (Exception e) { + unloadJar(urlClassLoader); + throw new RuntimeException("加载dll异常",e); + } + // 都加载成功后加入缓存 + addClassLoaderCache(projectId,urlClassLoader); } - // 都加载成功后加入缓存 - DllUtils.addClassLoaderCache(projectId,urlClassLoader); } } } -- Gitblit v1.9.3