I have been trying to figure out how to dynamically load classes from a jar file during runtime, knowing the name of the package to load them from. I have tried this: How to get all classes names in a package? It didnt work, I later realized it was for programs outside of jar files. I also took this snippet of code from another question, which I like a lot more:
URL[] urls = ....
URLClassLoader loader = new URLClassLoader(urls);
Class<?> cls = loader.loadClass("com.example.core.Main");
Module module = (Module) cls.newInstance();
But I don't see a way to load all classes in a defined package, like
Class<?>[] cls = loader.loadPackage("com.example.core");
How is this best solved? I have researched quite a bit and thought I was going at it the wrong way perhaps. Ultimately I just want to load all the classes in a package, without knowing anything but the package name, for an easier "Drop the class in" editing method.