Skip to content

Instantly share code, notes, and snippets.

@chilloutman
Created May 17, 2018 11:20
Show Gist options
  • Save chilloutman/0d7bb7cbb6eaa93e3dfcddaed96c7778 to your computer and use it in GitHub Desktop.
Save chilloutman/0d7bb7cbb6eaa93e3dfcddaed96c7778 to your computer and use it in GitHub Desktop.
ClassLoadersInspector.java
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