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 classNames = getClassName(packageName); for (String className : classNames) { System.out.println(className); } } public static List getClassName(String packageName) { String filePath = ClassLoader.getSystemResource("").getPath() + packageName.replace(".", "\\"); List fileNames = getClassName(filePath, null); return fileNames; } private static List getClassName(String filePath, List className) { List myClassName = new ArrayList(); 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; } }