I'm trying to make a maven plugin that needs to use reflection. I want a project to run the plugin, and give it the full name of a class in the project, and the plugin will load it by reflection to get info from it.
There's something strange with the classloader though, because it can't find the class when I use
Class.forName("package.MyClass");
Looking at the "Guide to Maven Classloading", I can't quite figure out if my plugin's classloader, when being run in a different project, has access to that project's classes.
ClassLoader
, do not make the currentClassLoader
its parent loader. If you do, a class that's in a dependency of your plugin may not be able to load a class that's only visible to your customClassLoader
because it may resolve the class using theClassLoader
that loaded it, which will be the Maven ClassRealm loader, not your loader. – Walkover