packageName为包名 eg:“com.test.demo”
public List<String> classCache = new ArrayList<>();
public void doRegister(String packageName){
URL url = this.getClass().getClassLoader().getResource(packageName.replaceAll("\\.", "/"));
File dir = new File(url.getFile());
for(File file : dir.listFiles()){
if(file.exists()) {
if(file.isDirectory()) {//如果是文件夹,递归继续查找
doRegister(packageName + "." + file.getName());
}
else {
String className = file.getName().replace(".class","");
String fullname = packageName + "." + className;
classCache.add(fullname.trim());
System.out.println(fullname);
}
}
}
}