Is it too late to answer.
I would say, its better to go by Libraries like ClassPathScanningCandidateComponentProvider or like Scannotations
But even after somebody wants to try some hands on it with classLoader, I have written some on my own to print the annotations from classes in a package:
public class ElementScanner {
public void scanElements(){
try {
//Get the package name from configuration file
String packageName = readConfig();
//Load the classLoader which loads this class.
ClassLoader classLoader = getClass().getClassLoader();
//Change the package structure to directory structure
String packagePath = packageName.replace('.', '/');
URL urls = classLoader.getResource(packagePath);
//Get all the class files in the specified URL Path.
File folder = new File(urls.getPath());
File[] classes = folder.listFiles();
int size = classes.length;
List> classList = new ArrayList>();
for(int i=0;i repoClass;
repoClass = Class.forName(classNamePath);
Annotation[] annotations = repoClass.getAnnotations();
for(int j =0;j
And in config File, you put the package name and unmarshall it to a class .