首页 > 解决方案 > 将文件附加到进程时出错

问题描述

我正在尝试将代理文件附加到特定进程我的代码:

   try{
       VirtualMachine virtualMachine = VirtualMachine.attach(pid);
       virtualMachine.loadAgent(agentFile.getAbsolutePath());
       System.out.println("Agent loaded!");

       virtualMachine.detach();
       System.out.println("detached");

   } catch (IOException | AttachNotSupportedException | AgentLoadException | 
            AgentInitializationException e){
        e.printStackTrace();
   }
}

错误:

       com.sun.tools.attach.AttachNotSupportedException: Unable to enqueue operation: the target VM does 
        not support attach mechanism

        at sun.tools.attach.WindowsVirtualMachine.<init>(WindowsVirtualMachine.java:64)
        at sun.tools.attach.WindowsAttachProvider.attachVirtualMachine(WindowsAttachProvider.java:69)
        at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
        at pl.alpaqdev.client.Util.attach(Util.java:46)
        at pl.alpaqdev.client.Main.main(Main.java:25)

我也尝试ByteBuddyAgent.attach(agentFile, pid);过使用byte-buddy,但我遇到了同样的错误。

标签: javajvm

解决方案


推荐阅读