Skip to content

Commit 4785719

Browse files
committed
Fix the usage of URLClassLoader
1 parent 05dc78a commit 4785719

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repositories {
1010
}
1111

1212
dependencies {
13-
implementation group: 'com.google.inject', name: 'guice', version: '4.2.2'
13+
implementation group: 'com.google.inject', name: 'guice', version: '5.1.0'
1414
implementation group: 'com.google.guava', name: 'guava', version: '31.0.1-jre'
1515
implementation group: 'com.moandjiezana.toml', name: 'toml4j', version: '0.7.2'
1616
implementation group: 'info.picocli', name: 'picocli', version: '4.1.4'

src/main/java/com/scalar/kelpie/modules/ModuleLoader.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,9 @@ public List<Injector> loadInjectors() throws ModuleLoadException {
6767

6868
private Module loadModule(String className, String jarPath) throws ModuleLoadException {
6969
try {
70-
URLClassLoader classLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader();
7170
URL jarUrl = new File(jarPath).toURI().toURL();
72-
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
73-
method.setAccessible(true);
74-
method.invoke(classLoader, jarUrl);
71+
URLClassLoader classLoader = new URLClassLoader(new URL[] { jarUrl }, Thread.currentThread().getContextClassLoader());
72+
Thread.currentThread().setContextClassLoader(classLoader);
7573

7674
@SuppressWarnings("unchecked")
7775
Class<Module> clazz = (Class<Module>) Class.forName(className, true, classLoader);

0 commit comments

Comments
 (0)