Package net.sourceforge.javautil.classloader.util

Source Code of net.sourceforge.javautil.classloader.util.ResourceSearch

package net.sourceforge.javautil.classloader.util;

import java.util.List;

import net.sourceforge.javautil.classloader.impl.ClassInfo;
import net.sourceforge.javautil.classloader.impl.ClassSearchInfo;
import net.sourceforge.javautil.classloader.source.ClassSource;
import net.sourceforge.javautil.classloader.source.LibDirectoryClassSource;
import net.sourceforge.javautil.common.io.impl.SystemDirectory;

/**
* This will allow one to search for a resource using all the libraries found in a particular directory recursively.
*
* @author elponderador
* @author $Author$
* @version $Id$
*/
public class ResourceSearch {
 
  /**
   * The first argument should be the directory to search in.
   * The second argument should be the resource name to search for.
   *
   * @param args Command line arguments
   */
  public static void main (String[] args) {
   
    if (args.length != 2) {
      System.err.println("Please provide the library directory and the resource name to search for.");
    } else {
     
      System.out.println("Searching for " + args[1] + " in " + args[0]);
      LibDirectoryClassSource lib = new LibDirectoryClassSource(new SystemDirectory(args[0]), true);
      List<ClassSource> sources = lib.getAllNonCompositeSources();
     
      for (ClassSource source : sources) {
        for (String name : source.getResourceNames()) {
          if (name.contains(args[1])) {
            System.out.println("Found: " + name + " in " + source);
          }
        }
      }
     
    }
   
  }

}
TOP

Related Classes of net.sourceforge.javautil.classloader.util.ResourceSearch

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.