private static void searchForJars ( final File file , List < File > jars ) { if ( file . isFile ( ) ) { if ( file . getAbsolutePath ( ) . toLowerCase ( ) . endsWith ( ".jar" ) ) { jars . add ( file ) ; LOG . debug ( "Found a jar: " + file . getAbsolutePath ( ) ) ; } } else if ( file . isDirectory ( ) ) { File [ ] files = file . listFiles ( ) ; if ( files == null ) { // if this is null, it's due to a security issue LOG . warn ( "Access denied to directory: " + file . getAbsolutePath ( ) ) ; } else { for ( File f : files ) { searchForJars ( f , jars ) ; } } } }
Recursive method to search for JAR files starting at a given level