我说的是reflections库。有没有可能获得我让代码编译的项目中包含的所有包的列表?
我已经用下面的代码括号尝试过了,但我不想插入项目名称。
Reflections reflections = new Reflections(/* Project name here... */);
Set<Class<? extends Object>> allClasses =
reflections.getSubTypesOf(Object.class);发布于 2016-12-17 09:26:05
使用的不是ronmamo/反射,而是Google Guava's ClassPath,可以这样做:
Set<ClassInfo> classInfos = ClassPath.from(Main.class.getClassLoader()).getTopLevelClassesRecursive("org.spongepowered");
List<String> packageNames = classInfos.stream().map(classInfo -> classInfo.getPackageName()).distinct().collect(Collectors.toList());https://stackoverflow.com/questions/17347567
复制相似问题