code: private static List<Class<?>> findClasses(File dir, String pkgname, boolean flat) throws ClassNotFoundException {
  
  		List<Class<?>> classes = new ArrayList<Class<?>>();
  		if (!dir.exists()) {
  			return classes;
  		}
  
  		File[] files = dir.listFiles();
  		for (File file : files) {
  			if (file.isDirectory() && !flat) {
  				classes.addAll(findClasses(file, pkgname + "." + file.getName(), flat));
  			} else if (file.getName().endsWith(".class")) {
  				classes.add(Class.forName(pkgname + '.' + file.getName().substring(0, file.getName().length() - 6)));
  			}
  		}
  
  		return classes;
  	}
docs: Recursive method used to find all classes in a given directory and
  subdirectories.
  
  @param dir base directory
  @param pkgname package name for classes found inside the base directory
  @param flat scan only one package level, do not dive into subdirectories
  @return Classes list
  @throws ClassNotFoundException