Here you can find the source of scanPackage(String path)
public static List<String> scanPackage(String path)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.net.URL; import java.util.Enumeration; import java.util.LinkedList; import java.util.List; public class Main { public static List<String> scanPackage(String path) { List<String> clazzs = new LinkedList<>(); try {// w w w .j a va 2 s . com path = path.replaceAll("\\.", "/"); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Enumeration<URL> resources = classLoader.getResources(path); File[] files = new File(resources.nextElement().getFile()).listFiles(); for (File file : files) { if (file.isDirectory()) { scanPackage(path + "/" + file.getName()); } else { String currentName = path.replace("/", ".") + "." + file.getName().substring(0, file.getName().length() - 6); clazzs.add(currentName); } } } catch (IOException e) { e.printStackTrace(); } return clazzs; } }