潘志宝
2025-03-03 142bcd3bd15e9ba6176bb2093eee22040da9bd8c
iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/matlab/common/utils/MatlabUtils.java
@@ -11,6 +11,7 @@
import com.mathworks.toolbox.javabuilder.*;
import com.mathworks.toolbox.javabuilder.internal.MWFunctionSignature;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.io.IOException;
@@ -183,7 +184,7 @@
    }
    /**
     * @description: 项目启动加载已发布的dll和jar
     * @description: 项目启动加载已发布的jar
     * @author: dzd
     * @date: 2024/10/10 11:58
     **/
@@ -192,23 +193,32 @@
        if (dir.exists() && dir.isDirectory()) {
            File[] files = dir.listFiles();
            if (null != files && files.length > 0) {
                HashMap<String,List<String>> projectIdJarFilePaths = new HashMap<>();
                for (File file : files) {
                    String fileName = file.getName();
                    if (fileName.endsWith(".jar")) {
                        String[] split = fileName.split(MdkConstant.SPLIT);
                        String projectId = split[0];
                        URLClassLoader urlClassLoader = null;
                        try {
                            // 加载新的jar
                            urlClassLoader = loadJar(projectId,file.getAbsolutePath());
                        } catch (Exception e) {
                            throw new RuntimeException("加载jar异常", e);
                        if (projectId != null) {
                            if (projectIdJarFilePaths.containsKey(projectId)) {
                                projectIdJarFilePaths.get(projectId).add(file.getAbsolutePath());
                            } else {
                                projectIdJarFilePaths.put(projectId,new ArrayList<String>(){{add(file.getAbsolutePath());}});
                            }
                        }
                        // 成功后加入缓存
                        addClassLoaderCache(projectId, urlClassLoader);
                    }
                }
                try {
                    if (!CollectionUtils.isEmpty(projectIdJarFilePaths)) {
                        for (Map.Entry<String, List<String>> entry : projectIdJarFilePaths.entrySet()) {
                            // 加载新的jar
                            loadJar(entry.getKey(),entry.getValue().toArray(new String[0]));
                        }
                    }
                } catch (Exception e) {
                    throw new RuntimeException("加载jar异常", e);
                }
            }
        }