Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Printing out the full path of a resource on the classpath (See related posts)

// displaying the full path of a resource found by the class loader on the classpath, here the log4j.xml file
String resourceName = "/log4j.xml"; // pay attention to the leading '/' !
URL location = AnyClass.class.getResource(resourceName);

if (location != null) {
    System.out.println(location.getPath());
} else {
    System.out.println(resourceName + " not found on the classpath");
}

You need to create an account or log in to post comments to this site.


Click here to browse all 4848 code snippets

Related Posts