3.入门实例
3.1 编写Agent启动类
public class TestAgent {
public static void premain(String agentArgs, Instrumentation inst){
System.out.println("premain start");
}
}
3.2 编写pomx.xml文件并将Agent启动类打包成jar文件
xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.3.1</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> </manifest> <manifestEntries> <Premain-Class>com.mmc.agent.TestAgent</Premain-Class> </manifestEntries> </archive> </configuration> </plugin> </plugins> </build>
使用package命令打包。
3.3 编写一个main方法,并运行
public class Main {
public static void main(String[] args) {
System.out.println("start");
}
}
增加启动参数:-javaagent:D:\webProjects\dubbo-master\dubbo-study-parent\java-agent\target\java-agent-1.0-SNAPSHOT.jar
路径为第二步打包的jar包的文件路径
3.4 运行情况
premain start
start
原文:https://www.cnblogs.com/javammc/p/12543267.html