使用Google反射库检索项目中所有包的列表?

时间:2013-06-27 15:45:01

标签: java packages google-reflections

我在谈论reflections lib。是否有可能获得项目中包含的所有包的列表,我让代码编译?

我已尝试使用以下代码括号,但我不想插入项目名称。

Reflections reflections = new Reflections(/* Project name here... */);

     Set<Class<? extends Object>> allClasses = 
         reflections.getSubTypesOf(Object.class);

1 个答案:

答案 0 :(得分:0)

使用非ronmamo / reflection而不是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());