I want to be able to navigate though all folders in a folder to load the classes inside those folders
My current code doesn't check all packages. It will only load classes if they're not packaged.
@SuppressWarnings({"rawtypes", "unchecked"})
public Class[] getClassesFromFolder() {
File folder = getFolder();
String thePath = folder.getPath();
ArrayList<Class<Script>> classes = new ArrayList<Class<Script>>();
try {
URL[] path = {new URL("file://" + thePath + "/Scripts/")};
File scriptFolder = new File(getFolder().getPath() + "/Scripts");
URLClassLoader cl = new URLClassLoader(path);
for (String script : scriptFolder.list()) {
if (script.contains(".class") && !script.contains("$")) {
String truePath = script.replace(".class", "");
try {
Class<?> scriptClass = (Class<?>) cl
.loadClass(truePath);
classes.add((Class<Script>) scriptClass);
} catch (Exception e) {
e.printStackTrace();
}
}
}
cl.close();
} catch (Exception e) {
e.printStackTrace();
}
return classes.toArray(new Class<?>[classes.size()]);
}