I am attempting to use the reflections library to get access to classes inside a package in my project. As per suggestions from the question below.
Can you find all classes in a package using reflection?
When running my method, size() on my set 0 is shown.
List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
classLoadersList.add(ClasspathHelper.contextClassLoader());
classLoadersList.add(ClasspathHelper.staticClassLoader());
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setScanners(new SubTypesScanner(false), new ResourcesScanner())
.setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])))
.filterInputsBy(newFilterBuilder().include(FilterBuilder.prefix("com.ruperts.java.Commands"))));
Set<Class<?>> classes = reflections.getSubTypesOf(Object.class);
System.out.println(classes.size());
I also tried setting the prefix to "" as per comment in other questions - still shows as no classes were found.
if anyone wonders a the simplest way to get the default package is having the prefix be an empty String -> "".
Is the issue with my package name?
Aucun commentaire:
Enregistrer un commentaire