Hello @Juan ,
You could use Reflections:
private Class<?>[] scanForTasks(String packageStr) {
Reflections reflections = new Reflections((new ConfigurationBuilder()).setScanners(new Scanner[]{new SubTypesScanner(), new TypeAnnotationsScanner()}).setUrls(ClasspathHelper.forPackage(packageStr, new ClassLoader[0])).filterInputsBy((new FilterBuilder()).includePackage(packageStr)));
Set classes = reflections.getTypesAnnotatedWith(Task.class);
Class[] taskArray = (Class[])classes.toArray(new Class[classes.size()]);
return taskArray;
}
}
Hope it helps!
To know more about Java, It's recommended to join our Java Training in Chennai today.