I am developing a program to mark algorithms submitted by a group of students; each student will submit their own .java files.
I would like to place these .java files into a folder and run my program. My program would then instantiate each class in the folder and add it to an arrayList so that I can run their code within my own.
Is there anyway I could do this, or something like this? Note: I do not know the exact amount of students. Any help would be greatly appreciated.
Best How To :
Hi I am not sure this is what you want but I think this is regarding how you get all classes in the folder and once you get them then you can easily run in your program.
First, You can't ask your students using the same name of the file becuase they can't be put into the same folder.
and then you can consider using a class in spring framework called ClassPathScanningCandidateComponentProvider that can do scan the classes in the pacakge:
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
// scan in org.example.package
Set<BeanDefinition> components = provider.findCandidateComponents("org/example/package");
for (BeanDefinition component : components)
Class cls = Class.forName(component.getBeanClassName());
// use class cls found
if the student has main method in their file you then call Student Class.main(arguments);
Have look at How do you find all subclasses of a given class in Java?