Skip to content

Commit 3bb3b8c

Browse files
committed
Switched from using URLClassloader to MangoLoader
1 parent b23d99a commit 3bb3b8c

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

src/main/java/org/mangorage/bootstrap/Bootstrap.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import java.io.IOException;
66
import java.nio.file.Path;
7-
import java.util.List;
87

98
import static org.mangorage.bootstrap.internal.Util.*;
109

@@ -35,6 +34,6 @@ public static void main(String[] args) throws IOException {
3534
}
3635
});
3736

38-
callMain(cfg.getMainClass(), args, cl);
37+
callMain(cfg.getMainClass(), args, moduleLayer.findModule("org.mangorage.mangobotcore").get());
3938
}
4039
}

src/main/java/org/mangorage/bootstrap/internal/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public ClassLoader constructClassloaders() {
117117

118118
// Create a new URLClassLoader with the current folder URL and the parent
119119
URL[] urls = Util.fetchJars(new File[]{folderFile});
120-
currentClassLoader = new URLClassLoader(urls, parentClassLoader);
120+
currentClassLoader = new MangoLoader(urls, parentClassLoader);
121121

122122
// The newly created classloader becomes the parent for the next iteration
123123
parentClassLoader = currentClassLoader;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.mangorage.bootstrap.internal;
2+
3+
import java.io.IOException;
4+
import java.net.URL;
5+
import java.net.URLClassLoader;
6+
7+
public final class MangoLoader extends URLClassLoader {
8+
public MangoLoader(URL[] urls, ClassLoader parent) {
9+
super(urls, parent);
10+
}
11+
12+
@Override
13+
protected URL findResource(String moduleName, String name) throws IOException {
14+
return super.findResource(name);
15+
}
16+
}

src/main/java/org/mangorage/bootstrap/internal/Util.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ public static String getModuleName(File jarFile) {
8686
return null; // Jar was either not modular or you're just unlucky
8787
}
8888

89-
public static void callMain(String className, String[] args, ClassLoader classLoader) {
89+
public static void callMain(String className, String[] args, Module module) {
9090
try {
91-
Class<?> clazz = Class.forName(className, false, classLoader);
91+
Class<?> clazz = Class.forName(className, false, module.getClassLoader());
9292
Method mainMethod = clazz.getMethod("main", String[].class);
9393

9494
// Make sure it's static and public

0 commit comments

Comments
 (0)