[英]Attach an agent remotely using Bytebuddy
I am trying to attach an agent for a process using bytebuddy .I found that we can use ByteBuddyAgent.attach(file,"18467");
我试图为使用bytebuddy的进程附加代理。我发现我们可以使用ByteBuddyAgent.attach(file,"18467");
for this. 为了这。 But when i am trying to do this following errors occurring. 但是,当我尝试执行此操作时,会发生以下错误。
This is agent i used 这是我使用的代理
File file = (new File("Agent.jar"));
Error 错误
java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@e26db604
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:378)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:227)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:202)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:189)
at common.netty.echo.EchoHttpServer.main(EchoHttpServer.java:95)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.bytebuddy.agent.Attacher.install(Attacher.java:77)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:373)
... 4 more
Caused by: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:106)
at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:63)
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
... 10 more
Any idea for this ? 有什么想法吗? and When i try to use this attachment from another agent as follows 当我尝试使用另一个代理的附件时,如下
public class Agent {
public static void premain(String args, Instrumentation instrumentation) {
System.out.println("Premain");
File file ;
try {
file = (new File("Agent.jar"));
ByteBuddyAgent.attach(file,"18467");
}
catch (Exception e)
{
e.printStackTrace();
}
}
I am getting this error 我收到此错误
Error 错误
java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@423f0955
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:378)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:227)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:202)
at net.bytebuddy.agent.ByteBuddyAgent.attach(ByteBuddyAgent.java:189)
at common.netty.echo.Agent.premain(Agent.java:111)
at common.netty.echo.EchoHttpServer.<clinit>(EchoHttpServer.java:56)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.bytebuddy.agent.Attacher.install(Attacher.java:77)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:373)
... 5 more
Caused by: java.lang.UnsatisfiedLinkError: Native Library /usr/lib/jvm/java-8-oracle/jre/lib/amd64/libattach.so already loaded in another classloader
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1907)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1845)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at sun.tools.attach.LinuxVirtualMachine.<clinit>(LinuxVirtualMachine.java:342)
at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:63)
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
... 11 more
Any suggestion on this!! 任何建议!
As for the first error message: does the target VM run the attachment listener? 至于第一条错误消息:目标VM是否运行附件侦听器? You can try to force starting the thread by setting -XX:+StartAttachListener
which should be set by default. 您可以尝试通过设置-XX:+StartAttachListener
来强制启动线程,默认情况下应将其设置。 What JVM version are you running? 您正在运行哪个JVM版本?
The other error message indicates that the attachment library was already loaded by another class loader. 另一个错误消息表明附件库已经由另一个类加载器加载。 See this answer for further details: java.lang.UnsatisfiedLinkError: Native Library XXX.so already loaded in another classloader 有关更多详细信息,请参见以下答案: java.lang.UnsatisfiedLinkError:本机库XXX.so已在另一个类加载器中加载
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.