Created
September 24, 2018 17:26
-
-
Save joakime/e6caf36ff30c48248e313440cae20495 to your computer and use it in GitHub Desktop.
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
package cloader; | |
import java.net.URL; | |
import java.util.Enumeration; | |
public class WhereIsThisComingFrom | |
{ | |
public static void main(String[] args) | |
{ | |
ClassLoader cl = Thread.currentThread().getContextClassLoader(); | |
locate(cl, "org/apache/juli/logging/Log.class"); | |
locate(cl, "org/eclipse/jetty/apache/jsp/JuliLog.class"); | |
} | |
public static void locate(ClassLoader cl, Class<?> clazz) | |
{ | |
String classAsResource = clazz.getName().replace('.', '/') + ".class"; | |
locate(cl, classAsResource); | |
} | |
public static void locate(ClassLoader cl, String resourceName) | |
{ | |
try | |
{ | |
Enumeration<URL> urls = cl.getResources(resourceName); | |
System.out.printf("Looking for: %s%n", resourceName); | |
while (urls.hasMoreElements()) | |
{ | |
URL url = urls.nextElement(); | |
System.out.printf(" - Found: %s%n", url.toExternalForm()); | |
} | |
} | |
catch (Throwable t) | |
{ | |
System.out.printf("Whoops: cannot locate: %s%n", resourceName); | |
t.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment