簡介¶
- mian方法之前,執行
- Java Agent 則是一個可以讓你在 Java runtime 即時改 bytecode 的技術。
內容¶
- 需要打包成jar
- META-INF/MANIFEST.MF
- java -javaagent:myagent.jar=thisIsAgentArgs -jar thisIsMain.jar
// MANIFEST.MF
Manifest-Version: 1.0
Premain-Class: tk.tommy.MyAgent
Can-Redefine-Classes: true
package tk.tommy;
public class MyAgent {
public static void premain(String agentArgs, Instrumentation instrumentation) {
System.out.println("=========premain方法执行========");
System.out.println(agentArgs);
System.out.println(instrumentation);
}
}
用 Java Agent 實作 AOP Spring Loaded is a JVM agent for reloading class file changes whilst a JVM is running