This is a quick tutorial on Byteman 2.0. You will need Eclipse and m2e to follow the steps below.
1. Download and unzip Byteman.
2. Create a new Maven Quickstart project in Eclipse.
3. Create the byteman script. This tutorial will use the filename quickbyteman.btm.
4. Set the content of the script.
RULE trace main entry CLASS App METHOD main AT ENTRY IF true DO traceln("entering main") ENDRULE RULE trace main exit CLASS App METHOD main AT EXIT IF true DO traceln("exiting main") ENDRULE
This script contains two rules, one injected on entry of App.main(), and another on exit. The code that runs calls the builtin function traceln(String) which prints to System.out().
5. Add the byteman javaagent to your Eclipse Run Configuration or in the Eclipse JRE. This tutorial will add it to the JRE.
-javaagent:bytemanlibbyteman.jar=script:quickbyteman.btm
6. Run App.java and you should see the “entering main” and “exiting main” in the console.
For more information about Byteman, visit the Byteman documentation and the Byteman Programmer’s Guide.