Skip to content

Commit

Permalink
Fix the usage of URLClassLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
komamitsu committed Dec 19, 2024
1 parent 05dc78a commit 4785719
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {
}

dependencies {
implementation group: 'com.google.inject', name: 'guice', version: '4.2.2'
implementation group: 'com.google.inject', name: 'guice', version: '5.1.0'
implementation group: 'com.google.guava', name: 'guava', version: '31.0.1-jre'
implementation group: 'com.moandjiezana.toml', name: 'toml4j', version: '0.7.2'
implementation group: 'info.picocli', name: 'picocli', version: '4.1.4'
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/scalar/kelpie/modules/ModuleLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ public List<Injector> loadInjectors() throws ModuleLoadException {

private Module loadModule(String className, String jarPath) throws ModuleLoadException {
try {
URLClassLoader classLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader();
URL jarUrl = new File(jarPath).toURI().toURL();
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
method.setAccessible(true);
method.invoke(classLoader, jarUrl);
URLClassLoader classLoader = new URLClassLoader(new URL[] { jarUrl }, Thread.currentThread().getContextClassLoader());
Thread.currentThread().setContextClassLoader(classLoader);

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

0 comments on commit 4785719

Please sign in to comment.