dengzedong
2024-10-10 a8f2f4e6f1a9173d7eb9779c7879674015c8cda0
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);
                    }
                }
            }