I get that you can run a method on classloading by using a static initializer.
The challenge is waiting for the classloader to load the class.
Assume my class to load is Initializer
. (No package).
You can trigger the classloader to load the class with a line like:
Initializer.class.getName();
But if you use a line like:
Initializer obj;
Then the classloader is not run.
ie by default, the classloader is not run for classes on the classpath. They have to be on the path of execution.
My question is: Is there a way for a class to trigger it's own classloading without being on the path of execution of a program?
The broader goal is to be able to drop a jar into an existing project, without modifying the original project, and have the extra method in the jar run on application startup.