解决 Agent JAR loaded but agent failed to initialize
在使用agent进行动态替换class时遇到错误
完整错误错误信息
com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initializeat sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:121)at com.sun.tools.attach.VirtualMachine.loadAgent(VirtualMachine.java:540)at com.style.note.base.instrument.Attache.main(Attache.java:18)
Disconnected from the target VM, address: '127.0.0.1:54359', transport: 'socket'
问题原因
public class CustomTransformer implements ClassFileTransformer {@Overridepublic byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {ClassPool classPool = ClassPool.getDefault();try {//重点 新的包名已经被修改为//com.style.note.base.instrument.BaseCtClass ctClass = classPool.get("com.style.note.base.Instrument.Base");CtMethod method = ctClass.getDeclaredMethod("process");method.insertBefore("{System.out.println(\"start\");}");method.insertAfter("{System.out.println(\"end \");}");return ctClass.toBytecode();} catch (NotFoundException | CannotCompileException | IOException e) {e.printStackTrace();}return null;}
}
//包名错误导致加载不到classCtClass ctClass = classPool.get("com.style.note.base.Instrument.Base");
解决办法 更新为正确的包名 即可成功加载类
其他问题
1.MANIFEST 文件错误 检查全类名是否正确
2.agent类的方法 agentmain 一定要正确
public class Agent {/*** agentmain** @param args args 注意参数为String 而不是String数组* @param instrumentation instrumentation*/public static void agentmain(String args, Instrumentation instrumentation) {//....}
}
解决 Agent JAR loaded but agent failed to initialize相关推荐
- idea弹窗 Placing the unmodified important.txt in the zip file with the agent jar in the same directo
破解idea后,启动弹框: This agent is for learning and research purposes only.Do nto user it for commercial pu ...
- oracle remote diagnostic agent,Oracle RDA-Remote Diagnostic Agent
Oracle RDA-Remote Diagnostic Agent <> RDA是Remote Diagnostic Agent 的简称,是Oracle用来收集.分析数据库的工具,运行该 ...
- Java Agent 调试,Java agent debug
Java Agent 调试,agent debug 一.简介 Java agent 是在另外一个 Java 应用("目标"应用)启动之前要执行的 Java 程序,这样 agent ...
- 成功解决Exception unhandled ImportError DLL load failed: 找不到指定的程序。 lib\imp.py, Line: 343
成功解决Exception "unhandled ImportError" DLL load failed: 找不到指定的程序. lib\imp.py, Line: 343 目录 ...
- 【已解决】运行Eclipse出错:Failed toload the JNI shared library
[已解决]运行Eclipse出错:Failed toload the JNI shared library [问题] 运行Android的ADT,即Eclipse出错: Failed to load ...
- ubuntu 重装 nvidia_nvidia-smi指令报错:Failed to initialize NVML: Driver解决
分配的新电脑,ubuntu18.04系统,nvidia的驱动都装好了,但是使用指令: nvidia-smi 报错: Failed to initialize NVML: Driver/library ...
- java -jar 找不到引用类_怎么解决java -jar找不到主类问题
怎么解决java -jar找不到主类问题 发布时间:2020-06-26 14:42:44 来源:亿速云 阅读:108 作者:Leah 怎么解决java -jar找不到主类问题?相信很多没有经验的人对 ...
- android引入开源项目方法,和解决android-support-v4.jar冲突问题
本文转自http://blog.csdn.net/a396901990/article/details/24197945,所有权力归原作者所有 本例子自己建了一个项目,需要导入slidemenu,和p ...
- 解决tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm.
报错内容 tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm. This ...
最新文章
- Debian手动修改ip地址
- 棋盘覆盖问题原理及演示程序
- 重构——71将领域和表述/显示分开(Separate Domain from Presentation)
- CG笔记之一——透视投影
- 我的makefile写法(一)
- 海康linux 密码忘记,linux下调用海康sdk
- 最好的Linux文件管理器,适用于 Linux 用户的 10 款优秀且免费的文件管理器
- python属于什么类型的选修课_河北大学python选修课00次作业
- 计算机硬件知识的意义,认识计算机硬件教案
- springboot定时器@Scheduled的cron,fixedRate,fixedDelay使用
- OpenCASCADE 获取面中心点法向
- 3W+2H:学习和思考问题的有效方式
- 基于微信小程序的消费金融系统
- Windows7建立共享WiFi设置(局域网配置)
- HTML(表单标签<form>)
- symbian与uiq开发教程
- 关于如何安装linux系统
- 谷歌SEO-外链策略
- 慕课网跟练系列——侧边栏导航跟随案例
- oracle erp和金蝶,ERP和金蝶软件有什么区别!