In the preceding section, you saw a tool that edits class files. However, it can be cumbersome to add yet another tool into the build process. An attractive alternative is to defer the bytecode engineering until load time, when the class loader loads the class.
Before Java SE 5.0, you had to write a custom class loader to achieve this task. Now, the instrumentation API has a hook for installing a bytecode transformer. The transformer must be installed before the
main method of the program is called. You can meet this requirement by defining an agent, a library that is loaded to monitor a program in some way. The agent code can carry out initializations in a
Here are the steps required to ...