得到包下所有类
来源:互联网 发布:mysql自动增长赋值 编辑:程序博客网 时间:2024/06/10 09:49
private static List<Class> getClass(String packageName) {
+ "/WebContent/WEB-INF/classes/" + packageName;
List<Class> fileNames = getClass(filePath, null);
return fileNames;
}
private static List<Class> getClass(String filePath, List<Class> className) {
List<Class> myClass = new ArrayList<Class>();
File file = new File(filePath);
File[] childFiles = file.listFiles();
for (File childFile : childFiles) {
if (childFile.isDirectory()) {
myClass.addAll(getClass(childFile.getPath(), myClass));
} else {
String childFilePath = childFile.getPath();
childFilePath = childFilePath.substring(childFilePath
.indexOf("\\classes") + 9, childFilePath
.lastIndexOf("."));
childFilePath = childFilePath.replace("\\", ".");
try {
myClass.add(Class.forName(childFilePath));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
return myClass;
}
File file = new File("");
// 为了打包后运行jar包可以得到地址
+ "/WebContent/WEB-INF/classes/" + packageName;
List<Class> fileNames = getClass(filePath, null);
return fileNames;
}
private static List<Class> getClass(String filePath, List<Class> className) {
List<Class> myClass = new ArrayList<Class>();
File file = new File(filePath);
File[] childFiles = file.listFiles();
for (File childFile : childFiles) {
if (childFile.isDirectory()) {
myClass.addAll(getClass(childFile.getPath(), myClass));
} else {
String childFilePath = childFile.getPath();
childFilePath = childFilePath.substring(childFilePath
.indexOf("\\classes") + 9, childFilePath
.lastIndexOf("."));
childFilePath = childFilePath.replace("\\", ".");
try {
myClass.add(Class.forName(childFilePath));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
return myClass;
}
0 0
- 得到包下所有类
- java得到一个包的所有类
- 获取包下的所有类
- android 扫描包下所有类
- 获取指定包下的所有类
- Java 获取包下的所有类
- Java 扫描包下所有类(包括jar包)
- 得到一个目录下所有文件(夹)
- 根据反射技术得到jar包中所有类,以及方法
- 根据反射技术得到jar包中所有类,以及方法
- java工具类-获取包下的所有类
- java工具类-获取包下的所有类
- java工具类 获取包下所有类
- java工具类 获取包下所有类
- java工具类 获取包下所有类
- Log4j之设置包下所有类的appender篇
- Android系统,动态找出一个包下所有的类
- 【正完成】java 反射一个包下的所有类
- 【新闻发布系统】——存储过程
- 金属材料工程专业大学生个人职业生涯规划
- js 格式化时间日期函数
- (常复习)poj 1015 dp+记录dp路径+转变最优子结构+区间映射
- spring和cxf整合
- 得到包下所有类
- grep、cut常见用法
- oracle隔离级别
- Innodb独立的undo tablespace
- ADB 常用命令
- HDU 3549 Flow Problem (简单最大流问题)
- LVS群集汇总,实现高可用
- spring动态生成bean
- PACKET_MMAP实现原理分析