Closed dyj2012 closed 6 years ago
private static Set getClassName(String filePath) throws ClassNotFoundException { Set classes= new HashSet(); filePath = ClassLoader.getSystemResource("").getPath() + filePath.replace(".", "/"); File file = new File(filePath);
File[] childFiles = file.listFiles(); if(childFiles==null){ throw new ClassNotFoundException(filePath+" is not found,Please check the aplication's annotation in @Sapi(controllers) "); } for (File childFile : childFiles) { String childFilePath = childFile.getPath(); childFilePath = childFilePath.substring(childFilePath.indexOf("/classes") + 9,childFilePath.length()); childFilePath=childFilePath.replaceAll(".class",""); childFilePath=childFilePath.replaceAll("/","."); classes.add(Class.forName(childFilePath)); } return classes; }
嗯,很好的建议,我当时想的是尽量绕开三方jar,但现在看来是绕不开了
private static Set getClassName(String filePath) throws ClassNotFoundException {
Set classes= new HashSet();
filePath = ClassLoader.getSystemResource("").getPath() + filePath.replace(".", "/");
File file = new File(filePath);