| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | /** |
| | | * @description: 项目启动加载已发布的dll和jar |
| | | * @description: 项目启动加载已发布的jar |
| | | * @author: dzd |
| | | * @date: 2024/10/10 11:58 |
| | | **/ |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |