Skip to content

Commit

Permalink
Fix breaking something depends on system classloader
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Dec 12, 2021
1 parent a5437dc commit 90e8e5c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.azisaba</groupId>
<artifactId>Log4j2Fix</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/net/azisaba/log4j2Fix/Log4j2Fix.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import java.io.InputStreamReader;
import java.lang.instrument.Instrumentation;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -28,9 +26,9 @@ public static void main(String[] args) throws IOException {
}
String main = arguments.remove(0);
File file = new File(main);
ClassLoader classLoader;
if (file.exists()) {
classLoader = new URLClassLoader(new URL[]{file.toURI().toURL()}, Log4j2Fix.class.getClassLoader());
System.out.println("Using " + file.getAbsolutePath() + " for classpath");
NativeUtil.appendToSystemClassLoaderSearch(file.getAbsolutePath());
ZipFile zipFile = new ZipFile(file);
ZipEntry zipEntry = zipFile.getEntry("META-INF/MANIFEST.MF");
if (zipEntry == null) {
Expand Down Expand Up @@ -59,11 +57,9 @@ public static void main(String[] args) throws IOException {
main = arguments.remove(0);
}
}
} else {
classLoader = Log4j2Fix.class.getClassLoader();
}
try {
Class<?> clazz = Class.forName(main, false, classLoader);
Class<?> clazz = Class.forName(main);
Method m = clazz.getMethod("main", String[].class);
m.invoke(null, (Object) arguments.toArray(new String[0]));
} catch (ReflectiveOperationException e) {
Expand Down

0 comments on commit 90e8e5c

Please sign in to comment.