public static Collection < String > getClasspathResources ( final Pattern searchPattern ) { final List < String > resources = new ArrayList <> ( ) ; final ClassLoader cl = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( hasJavaWebstartLibrary ( ) && cl instanceof JNLPClassLoaderIf ) { LOGGER . log ( USE_JNLP_CLASSLOADER ) ; final JNLPClassLoaderIf wsLoader = ( JNLPClassLoaderIf ) cl ; // System.out.println("URLs "+ wsLoader.getURLs()); for ( final JARDesc jd : wsLoader . getLaunchDesc ( ) . getResources ( ) . getLocalJarDescs ( ) ) { try { final JarFile jarFile = wsLoader . getJarFile ( jd . getLocation ( ) ) ; LOGGER . log ( PARSE_CACHED_JAR_FILE , jarFile . getName ( ) , jd . getLocationString ( ) ) ; resources . addAll ( getResources ( jarFile . getName ( ) , searchPattern , true ) ) ; } catch ( final IOException e ) { LOGGER . log ( CANT_READ_CACHED_JAR_FILE , jd . getLocation ( ) ) ; } } } else { LOGGER . log ( USE_DEFAULT_CLASSLOADER ) ; final String [ ] classpathEntries = CLASSPATH . split ( CLASSPATH_SEPARATOR ) ; for ( final String urlEntry : classpathEntries ) { // Parse the classpath entry and apply the given pattern as filter resources . addAll ( getResources ( urlEntry , searchPattern , false ) ) ; } } // Sort resources Collections . sort ( resources ) ; return resources ; }
Retrieve all resources that match the search pattern from the java . class . path .