3

I'm talking about the reflections lib. Is there any possibility to get a list of all packages which are included in the project where I let the code compile?

I've tried it with the following code bracket but I don't want to insert a project name.

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

     Set<Class<? extends Object>> allClasses = 
         reflections.getSubTypesOf(Object.class);
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
MKorsch
  • 3,822
  • 3
  • 16
  • 21

1 Answers1

0

Using not ronmamo/reflections but Google Guava's ClassPath, one can do something like this:

Set<ClassInfo> classInfos = ClassPath.from(Main.class.getClassLoader()).getTopLevelClassesRecursive("org.spongepowered");
List<String> packageNames = classInfos.stream().map(classInfo -> classInfo.getPackageName()).distinct().collect(Collectors.toList());
vorburger
  • 3,439
  • 32
  • 38