Skip to content

Commit 90e8e5c

Browse files
committed
Fix breaking something depends on system classloader
1 parent a5437dc commit 90e8e5c

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>net.azisaba</groupId>
88
<artifactId>Log4j2Fix</artifactId>
9-
<version>1.0.0</version>
9+
<version>1.0.1</version>
1010

1111
<properties>
1212
<maven.compiler.source>8</maven.compiler.source>

src/main/java/net/azisaba/log4j2Fix/Log4j2Fix.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import java.io.InputStreamReader;
1111
import java.lang.instrument.Instrumentation;
1212
import java.lang.reflect.Method;
13-
import java.net.URL;
14-
import java.net.URLClassLoader;
1513
import java.util.ArrayList;
1614
import java.util.Arrays;
1715
import java.util.List;
@@ -28,9 +26,9 @@ public static void main(String[] args) throws IOException {
2826
}
2927
String main = arguments.remove(0);
3028
File file = new File(main);
31-
ClassLoader classLoader;
3229
if (file.exists()) {
33-
classLoader = new URLClassLoader(new URL[]{file.toURI().toURL()}, Log4j2Fix.class.getClassLoader());
30+
System.out.println("Using " + file.getAbsolutePath() + " for classpath");
31+
NativeUtil.appendToSystemClassLoaderSearch(file.getAbsolutePath());
3432
ZipFile zipFile = new ZipFile(file);
3533
ZipEntry zipEntry = zipFile.getEntry("META-INF/MANIFEST.MF");
3634
if (zipEntry == null) {
@@ -59,11 +57,9 @@ public static void main(String[] args) throws IOException {
5957
main = arguments.remove(0);
6058
}
6159
}
62-
} else {
63-
classLoader = Log4j2Fix.class.getClassLoader();
6460
}
6561
try {
66-
Class<?> clazz = Class.forName(main, false, classLoader);
62+
Class<?> clazz = Class.forName(main);
6763
Method m = clazz.getMethod("main", String[].class);
6864
m.invoke(null, (Object) arguments.toArray(new String[0]));
6965
} catch (ReflectiveOperationException e) {

0 commit comments

Comments
 (0)