简单实现递归扫描包得到包下的Class类的全路径
public void recursionScanFile(String scanPackagePath) {
String newScanPackagePath = scanPackagePath.replaceAll("\\.", "/");
System.out.println(newScanPackagePath);
URL resource = this.getClass().getClassLoader().getResource(newScanPackagePath);
Assert.notNull(resource, "resource is null");
String filepath = resource.getFile();
File file = new File(filepath);
File[] files = file.listFiles();
Assert.notNull(files, "files is null");
for (File subFile : files) {
if (!subFile.isDirectory() && subFile.getName().endsWith(".class")) {
String className = subFile.getName().replaceAll("\\.class", "");
String classFullPath = scanPackagePath + "." + className;
System.out.println("classFullPath = " + classFullPath);
} else {
String newPath = scanPackagePath + "." + subFile.getName();
//进行递归
recursionScanFile(newPath);
}
}
}