From 8f9e8e0180b04abd324f05cf28423609231423f8 Mon Sep 17 00:00:00 2001 From: liaokun Date: Tue, 8 Oct 2024 14:18:36 +0800 Subject: [PATCH] fix: NoClassDefFoundError when multiple arex-agent are started on the same server --- arex-agent/src/main/java/io/arex/agent/JarUtils.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/arex-agent/src/main/java/io/arex/agent/JarUtils.java b/arex-agent/src/main/java/io/arex/agent/JarUtils.java index 4c30f16c1..89be2676b 100644 --- a/arex-agent/src/main/java/io/arex/agent/JarUtils.java +++ b/arex-agent/src/main/java/io/arex/agent/JarUtils.java @@ -4,8 +4,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -17,9 +15,6 @@ public class JarUtils { private static final String DELIMITER = ";"; private static final String NESTED_BOOTSTRAP_JARS_PATH = "Nested-BootStrap-Jars-Path"; - private static final File TMP_FILE = new File(AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty("java.io.tmpdir"))); - private static final String TEMP_DIR_BOOTSTRAP = TMP_FILE.getAbsolutePath() + File.separator + "arex" + File.separator + "bootstrap"; - /** * ex: * arex-agent.jar @@ -41,7 +36,7 @@ public static List extractNestedBootStrapJar(File file) { for (String jarPath : jarPaths) { JarEntry jarEntry = jarFile.getJarEntry(jarPath); if (jarEntry.getName().endsWith(JAR_SUFFIX)) { - jarFiles.add(extractNestedBootStrapJar(jarFile, jarEntry, jarEntry.getName())); + jarFiles.add(extractNestedBootStrapJar(jarFile, jarEntry, jarEntry.getName(), file.getParentFile())); } } return jarFiles; @@ -51,9 +46,9 @@ public static List extractNestedBootStrapJar(File file) { } } - private static File extractNestedBootStrapJar(JarFile file, JarEntry entry, String entryName) throws IOException { + private static File extractNestedBootStrapJar(JarFile file, JarEntry entry, String entryName, File parentDir) throws IOException { String fileName = new File(entryName).getName(); - File outputFile = createFile(TEMP_DIR_BOOTSTRAP + File.separator + fileName); + File outputFile = createFile(parentDir.getAbsolutePath() + File.separator + "bootstrap" + File.separator + fileName); try(InputStream inputStream = file.getInputStream(entry); FileOutputStream outputStream = new FileOutputStream(outputFile)) { byte[] buffer = new byte[1024];