code: protected static Class<?>[] getClasses(String pkgname, boolean flat) {
  
  		List<File> dirs = new ArrayList<File>();
  		List<Class<?>> classes = new ArrayList<Class<?>>();
  
  		ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  		String path = pkgname.replace('.', '/');
  
  		Enumeration<URL> resources = null;
  		try {
  			resources = classLoader.getResources(path);
  		} catch (IOException e) {
  			throw new RuntimeException("Cannot read path " + path, e);
  		}
  
  		while (resources.hasMoreElements()) {
  			URL resource = resources.nextElement();
  			dirs.add(new File(resource.getFile()));
  		}
  
  		for (File directory : dirs) {
  			try {
  				classes.addAll(findClasses(directory, pkgname, flat));
  			} catch (ClassNotFoundException e) {
  				throw new RuntimeException("Class not found", e);
  			}
  		}
  
  		return classes.toArray(new Class<?>[classes.size()]);
  	}
docs: Scans all classes accessible from the context class loader which belong
  to the given package and subpackages.
  
  @param packageName The base package
  @param flat scan only one package level, do not dive into subdirectories
  @return The classes
  @throws ClassNotFoundException
  @throws IOException