I can imagine two simple (-ish) ways to do this in Java:
Method # 1 - Static Initializers
For instance:
public class Test { static { System.err.println("Static initializer first"); } public static void main(String[] args) { System.err.println("In main"); } }
Method # 2 is the main proxy.
public class ProxyMain { public static void main(String[] args) { String classname = args[0];
Then you run this as:
java <jvm-options> ... ProxyMain <real-Main> arg ...
There is also a third method, but this requires some “extreme measures”. Basically, you have to create your own JVM launcher that uses a different scheme to run the application. Ask this to do unnecessary things before loading the entry point class and calling its main method. (Or do something completely different.)
You can even replace the default class loader; e.g. How to change the default class loader in Java?
source share