Created
May 17, 2018 11:20
-
-
Save chilloutman/0d7bb7cbb6eaa93e3dfcddaed96c7778 to your computer and use it in GitHub Desktop.
ClassLoadersInspector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static java.lang.System.out; | |
import static java.util.Arrays.stream; | |
import static java.util.stream.Collectors.joining; | |
import static java.util.stream.Stream.generate; | |
import java.net.URL; | |
import java.net.URLClassLoader; | |
class ClassLoadersInspector { | |
static void inspectClassLoaders (ClassLoader loader) { | |
if (loader == null) { | |
return; | |
} | |
out.println(generate( () -> "-").limit(80).collect(joining())); | |
out.println("toString() = " + loader); | |
if (loader instanceof URLClassLoader) { | |
URLClassLoader urlLoader = (URLClassLoader) loader; | |
String urls = stream(urlLoader.getURLs()) | |
.map(URL::toString) | |
.map(s -> "- " + s) | |
.collect(joining("\n", "getURLs() =\n", "\n")); | |
out.println(urls); | |
} | |
out.println(generate( () -> "-").limit(80).collect(joining())); | |
inspectClassLoaders(loader.getParent()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment