public static URL getURL ( String confName , ClassLoader classLoader , Class cls ) { URL url = null ; // User home String userHome = System . getProperty ( "user.home" ) ; if ( userHome . endsWith ( "\\" ) || userHome . endsWith ( "/" ) ) { url = getURLForFile ( userHome + confName ) ; } else { url = getURLForFile ( userHome + "/" + confName ) ; } // Working directory if ( url == null ) { url = getURLForFile ( confName ) ; } // check Class folder if ( cls != null ) { URL urlResource = cls . getResource ( confName ) ; if ( urlResource != null ) { url = urlResource ; } } // check META-INF directories for all known ClassLoaders if ( url == null && classLoader != null ) { ClassLoader confClassLoader = classLoader ; if ( confClassLoader != null ) { url = confClassLoader . getResource ( "META-INF/" + confName ) ; } } if ( url == null ) { ClassLoader confClassLoader = ConfFileUtils . class . getClassLoader ( ) ; if ( confClassLoader != null && confClassLoader != classLoader ) { url = confClassLoader . getResource ( "META-INF/" + confName ) ; } } if ( url == null && cls != null ) { ClassLoader confClassLoader = cls . getClassLoader ( ) ; if ( confClassLoader != null && confClassLoader != classLoader ) { url = confClassLoader . getResource ( "META-INF/" + confName ) ; } } if ( url == null ) { ClassLoader confClassLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( confClassLoader != null && confClassLoader != classLoader ) { url = confClassLoader . getResource ( "META-INF/" + confName ) ; } } if ( url == null ) { ClassLoader confClassLoader = ClassLoader . getSystemClassLoader ( ) ; if ( confClassLoader != null && confClassLoader != classLoader ) { url = confClassLoader . getResource ( "META-INF/" + confName ) ; } } return url ; }
Return the URL for a given conf file