I am working on a project that creates Java classes from xsd. At run-time, I want to create classes and read names of these classes. However, when I first run the project (before classes are created) it gives me an error that says "java.lang.ClassNotFoundException: generated.classes.AddressType" . If I run again , without changing anything (classes are created at this point) , it does not give me an error. I used "com.sun.tools.xjc.api" for creating classes. When I want to read class names, I simply do that
File folder = new File(System.getProperty("user.dir")+"\\src\\generated\\classes");
File[] listOfFiles = null;
List<String> namesOfClasses = new ArrayList<>();
listOfFiles=folder.listFiles();
for(File file: listOfFiles){
try {
if(!file.getName().equals("ObjectFactory.java")){
String classname="generated.classes."+file.getName().substring(0, file.getName().length() - 5);
namesOfClasses.add(classname);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return namesOfClasses;
It seems , new created classes cannot be seen at runtime. How can I make this classes read at runtime?