1. 代码部分可以参考
Java查看动态代理生成的代码_fengyuyeguirenenen的博客-CSDN博客
2. idea建一个maven项目
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.wyx</groupId> <artifactId>agent</artifactId> <version>1.0-SNAPSHOT</version> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile> </archive> </configuration> </plugin> </plugins> </build> </project>
2.2 MANIFEST.MF:
Manifest-Version: 1.0
Premain-Class: ctgu.jagent.CustomAgent
2.3 maven intall
3. 新建一个项目引入agent
启动参数:-javaagent:C:\Users\21442\.m2\repository\com\wyx\agent\1.0-SNAPSHOT\agent-1.0-SNAPSHOT.jar