在使用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相关推荐

  1. 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 ...

  2. oracle remote diagnostic agent,Oracle RDA-Remote Diagnostic Agent

    Oracle RDA-Remote Diagnostic Agent <> RDA是Remote Diagnostic Agent 的简称,是Oracle用来收集.分析数据库的工具,运行该 ...

  3. Java Agent 调试,Java agent debug

    Java Agent 调试,agent debug 一.简介 Java agent 是在另外一个 Java 应用("目标"应用)启动之前要执行的 Java 程序,这样 agent ...

  4. 成功解决Exception unhandled ImportError DLL load failed: 找不到指定的程序。 lib\imp.py, Line: 343

    成功解决Exception "unhandled ImportError" DLL load failed: 找不到指定的程序. lib\imp.py, Line: 343 目录 ...

  5. 【已解决】运行Eclipse出错:Failed toload the JNI shared library

    [已解决]运行Eclipse出错:Failed toload the JNI shared library [问题] 运行Android的ADT,即Eclipse出错: Failed to load ...

  6. ubuntu 重装 nvidia_nvidia-smi指令报错:Failed to initialize NVML: Driver解决

    分配的新电脑,ubuntu18.04系统,nvidia的驱动都装好了,但是使用指令: nvidia-smi 报错: Failed to initialize NVML: Driver/library ...

  7. java -jar 找不到引用类_怎么解决java -jar找不到主类问题

    怎么解决java -jar找不到主类问题 发布时间:2020-06-26 14:42:44 来源:亿速云 阅读:108 作者:Leah 怎么解决java -jar找不到主类问题?相信很多没有经验的人对 ...

  8. android引入开源项目方法,和解决android-support-v4.jar冲突问题

    本文转自http://blog.csdn.net/a396901990/article/details/24197945,所有权力归原作者所有 本例子自己建了一个项目,需要导入slidemenu,和p ...

  9. 解决tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm.

    报错内容 tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm. This ...

最新文章

  1. Debian手动修改ip地址
  2. 棋盘覆盖问题原理及演示程序
  3. 重构——71将领域和表述/显示分开(Separate Domain from Presentation)
  4. CG笔记之一——透视投影
  5. 我的makefile写法(一)
  6. 海康linux 密码忘记,linux下调用海康sdk
  7. 最好的Linux文件管理器,适用于 Linux 用户的 10 款优秀且免费的文件管理器
  8. python属于什么类型的选修课_河北大学python选修课00次作业
  9. 计算机硬件知识的意义,认识计算机硬件教案
  10. springboot定时器@Scheduled的cron,fixedRate,fixedDelay使用
  11. OpenCASCADE 获取面中心点法向
  12. 3W+2H:学习和思考问题的有效方式
  13. 基于微信小程序的消费金融系统
  14. Windows7建立共享WiFi设置(局域网配置)
  15. HTML(表单标签<form>)
  16. symbian与uiq开发教程
  17. 关于如何安装linux系统
  18. 谷歌SEO-外链策略
  19. 慕课网跟练系列——侧边栏导航跟随案例
  20. oracle erp和金蝶,ERP和金蝶软件有什么区别!

热门文章

  1. Day 。 9 我来个初级的文字游戏《魔兽世界。巫妖王之怒》
  2. R语言中的异常处理和eval函数
  3. 带你玩转超级列表框(1-4)雪山灵狐
  4. 54. 流编辑器sed技术概览
  5. 我和Double Lift的故事(三)——应用篇
  6. 免费开源动画制作软件推荐(新手必备)
  7. 【C】三子棋 VS 扫雷
  8. 权力的游戏刷声望辅助【多开辅助】权力的游戏手游辅助挂机刷石油资源采集脚本
  9. mybatis不区分大小写问题
  10. Kmeans聚类时K值选择的方法