Tutorial by Examples

Firstly, make sure that the agent being used has the following attributes in the Manifest.mf: Can-Redefine-Classes: true Can-Retransform-Classes: true Starting a java agent will let the agent access the class Instrumentation. With Instrumentation you can call addTransformer(ClassFileTransformer...
Agents can be added to a JVM at runtime. To load an agent you will need to use the Attach API's VirtualMachine.attatch(String id). You can then load a compiled agent jar with the following method: public static void loadAgent(String agentPath) { String vmName = ManagementFactory.getRuntimeMXBe...
The Premain class will contain the method "premain(String agentArgs Instrumentation inst)" Here is an example: import java.lang.instrument.Instrumentation; public class PremainExample { public static void premain(String agentArgs, Instrumentation inst) { System.out.print...

Page 1 of 1