Skip to content

fix: NoClassDefFoundError when multiple arex-agent are started on the same server #572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions arex-agent/src/main/java/io/arex/agent/JarUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String>) () -> 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
Expand All @@ -41,7 +36,7 @@ public static List<File> 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;
Expand All @@ -51,9 +46,9 @@ public static List<File> 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];
Expand Down