private static URL getClassPathURL ( String resourceName , URL resourceURL ) { try { if ( "file" . equals ( resourceURL . getProtocol ( ) ) ) { String path = resourceURL . getFile ( ) ; // Compute the directory container the class. int endIdx = path . length ( ) - resourceName . length ( ) ; if ( endIdx > 1 ) { // If it is not the root directory, return the end index to remove the trailing '/'. endIdx -- ; } return new URL ( "file" , "" , - 1 , path . substring ( 0 , endIdx ) ) ; } if ( "jar" . equals ( resourceURL . getProtocol ( ) ) ) { String path = resourceURL . getFile ( ) ; return URI . create ( path . substring ( 0 , path . indexOf ( "!/" ) ) ) . toURL ( ) ; } } catch ( MalformedURLException e ) { throw Throwables . propagate ( e ) ; } throw new IllegalStateException ( "Unsupported class URL: " + resourceURL ) ; }
Find the classpath that contains the given resource .