Exemple #1
0
  private static List<String> findAllJarsInPaths(String... pathStrs) {
    final LinkedHashSet<String> pathSet = new LinkedHashSet<String>();

    FileVisitor visitor =
        new FileVisitor() {

          @Override
          public void visit(File file) {
            String name = file.getName();
            if (name.endsWith(".jar")) {
              pathSet.add(file.getPath());
            }
          }
        };

    for (String path : pathStrs) {
      File file = new File(path);
      traverse(file, visitor);
    }

    final List<String> toRet = new ArrayList<String>();
    for (String p : pathSet) {
      toRet.add(p);
    }
    return toRet;
  }
Exemple #2
0
 private static void traverse(File file, FileVisitor visitor) {
   if (file.isDirectory()) {
     File childs[] = file.listFiles();
     if (childs.length > 0) {
       for (int i = 0; i < childs.length; i++) {
         File child = childs[i];
         traverse(child, visitor);
       }
     }
   } else {
     visitor.visit(file);
   }
 }