You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.6 KiB
42 lines
1.6 KiB
import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class test {
|
|
public static void main(String[] args) {
|
|
String packageName = "com.loygra.lsm.service.impl.gumi.task";
|
|
|
|
List<String> classNames = getClassName(packageName);
|
|
for (String className : classNames) {
|
|
System.out.println(className);
|
|
}
|
|
}
|
|
|
|
public static List<String> getClassName(String packageName) {
|
|
String filePath = ClassLoader.getSystemResource("").getPath() + packageName.replace(".", "\\");
|
|
List<String> fileNames = getClassName(filePath, null);
|
|
return fileNames;
|
|
}
|
|
|
|
private static List<String> getClassName(String filePath, List<String> className) {
|
|
List<String> myClassName = new ArrayList<String>();
|
|
File file = new File(filePath);
|
|
File[] childFiles = file.listFiles();
|
|
for (File childFile : childFiles) {
|
|
if (childFile.isDirectory()) {
|
|
myClassName.addAll(getClassName(childFile.getPath(), myClassName));
|
|
} else {
|
|
String childFilePath = childFile.getPath();
|
|
int startPos = childFilePath.indexOf("\\classes") + 9;
|
|
if(startPos==8) {
|
|
startPos= childFilePath.indexOf("\\bin") + 5;
|
|
}
|
|
childFilePath = childFilePath.substring(startPos, childFilePath.lastIndexOf("."));
|
|
childFilePath = childFilePath.replace("\\", ".");
|
|
myClassName.add(childFilePath);
|
|
}
|
|
}
|
|
|
|
return myClassName;
|
|
}
|
|
}
|
|
|