I'm trying to load classes that I defined here such as DemoApplication.class and Test.class. I'm using guava 31.0.1-jre, and used ClassPath.from().getAllClasses(), but it seems to only get runtime classes and these two classes I want are not being loaded. I'm not sure if what I'm doing is totally in the wrong way.
public static void main(String[] args) throws ClassNotFoundException, IOException {
File file = new File("C:\\DemoApplication.class");
URL url = file.toURI().toURL();
File file1 = new File("C:\\Test.class");
URL url1 = file1.toURI().toURL();
int count=0;
URLClassLoader classLoader = new URLClassLoader(new URL[]{url,url1});
for (ClassPath.ClassInfo classInfo : ClassPath.from(classLoader).getAllClasses()) {
if (classInfo.getName().contains("DemoApplication")){
// I didn't get any output here
System.out.println(classInfo.getName());
}
}
System.out.println(count);
}