Skip to content

Commit 4183850

Browse files
committed
addPath: Avoid adding same path again and again
1 parent 2a6f0c8 commit 4183850

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main/java/scalive/Classpath.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.lang.reflect.Method;
55
import java.net.URL;
66
import java.net.URLClassLoader;
7+
import java.util.Arrays;
78

89
public class Classpath {
910
private static Method addURL = getAddURL();
@@ -44,8 +45,9 @@ public static String findJar(String[] jarpaths, String jarbase) throws Exception
4445
}
4546

4647
public static void addPath(URLClassLoader cl, String path) throws Exception {
47-
URL url = new File(path).toURI().toURL();
48-
addURL.invoke(cl, url);
48+
URL url = new File(path).toURI().toURL();
49+
URL[] urls = cl.getURLs();
50+
if (!Arrays.asList(urls).contains(url)) addURL.invoke(cl, url);
4951
}
5052

5153
/** Combination of findJar and addPath. */

0 commit comments

Comments
 (0)