There is no startup hook in Java. Your choices are (in the order I would recommend them).
- Use a startup callback feature of the framework you're running in (i.e. Servlets, Spring, etc). This would also include simply having whoever is writing the main method give you a callback.
- Wrap the
main(String[])
method with your ownmain(String[])
method and then delegate after calling your main from the commandline. - Create a java agent library with a
Premain-Class
definition in your jar manifest then add the agent to the JVM on the command line.
The last two options require you to add or changes things on the command-line.