public static String locate ( String className , ClassLoader classLoader ) { String resource = new String ( className ) ; // format the file name into a valid resource name if ( ! resource . startsWith ( "/" ) ) { resource = "/" + resource ; } resource = resource . replace ( ' ' , ' ' ) ; resource = resource + ".class" ; // attempt to locate the file using the class loader URL classUrl = classLoader . getResource ( resource ) ; if ( classUrl == null && classLoader == ClasspathUtil . class . getClassLoader ( ) ) { // Apparently clazz.getResource() works sometimes when clazz.getClassLoader().getResource() does not. // TODO: why? classUrl = ClasspathUtil . class . getResource ( resource ) ; } if ( classUrl == null ) { return "\nClass not found: [" + className + "]" ; } else { return classUrl . getFile ( ) ; } }
Finds the location of the version of a particular class that will be used by the Java runtime . Output goes to standard out .