private URL [ ] findResourcesInUrls ( String classRelativePath , URL [ ] urls ) { List < URL > list = new ArrayList < URL > ( ) ; for ( URL url : urls ) { if ( AllowedProtocol . isValidProtocol ( url . getProtocol ( ) . toUpperCase ( ) ) && url . getPath ( ) . endsWith ( ".jar" ) ) { try { JarFile jarFile = new JarFile ( URLDecoder . decode ( url . getFile ( ) , Constants . CHARSET_UTF8 ) ) ; // Checking the dependencies of this jar file Manifest manifest = jarFile . getManifest ( ) ; if ( manifest != null ) { String classPath = manifest . getMainAttributes ( ) . getValue ( "Class-Path" ) ; // Scan all entries in the classpath if they are // specified in the jar if ( ! StringUtils . isEmpty ( classPath ) ) { List < URL > subList = new ArrayList < URL > ( ) ; for ( String cpEntry : classPath . split ( " " ) ) { try { subList . add ( new URL ( cpEntry ) ) ; } catch ( MalformedURLException e ) { URL subResources = ClasspathReader . class . getClassLoader ( ) . getResource ( cpEntry ) ; if ( subResources != null ) { subList . add ( subResources ) ; } // logger.warn("Incorrect URL in the classpath of a jar file [" // + url.toString() // + "]: " + cpEntry); } } list . addAll ( Arrays . asList ( findResourcesInUrls ( classRelativePath , subList . toArray ( new URL [ subList . size ( ) ] ) ) ) ) ; } } JarEntry present = jarFile . getJarEntry ( classRelativePath + ".class" ) ; if ( present != null ) { list . add ( url ) ; } } catch ( IOException e ) { logger . warn ( "Error during loading from context , Caused by:" + e . getMessage ( ) ) ; } } else if ( url . getPath ( ) . endsWith ( "/" ) ) { File file = new File ( url . getPath ( ) + classRelativePath + ".class" ) ; if ( file . exists ( ) ) { try { list . add ( file . toURL ( ) ) ; } catch ( MalformedURLException e ) { throw new ResourceReadingException ( e ) ; } } } } return list . toArray ( new URL [ list . size ( ) ] ) ; }
Scan class resource in the provided urls with the additional Class - Path of each jar checking