我正在尝试在正在运行的进程上放置一个java代理。我的问题是我无法连接到vm,因为我遇到以下错误:
java.util.ServiceConfigurationError: com.sun.tools.attach.spi.AttachProvider: Provider sun.tools.attach.WindowsAttachProvider could not be instantiated
com.sun.tools.attach.AttachNotSupportedException: no providers installed
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:203)
at io.github.giantnuker.tailor.transform.JavaAgent.attachAgent(JavaAgent.java:31)
重要的部分似乎是 com.sun.tools.attach.AttachNotSupportedException: no providers installed
这是产生错误的类:
public class JavaAgent {
public static void agentmain(String stringArguments, Instrumentation instrumentation) {
System.out.println("hi from agentmain");
}
private static String getPid() {
RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
String pid = bean.getName();
if (pid.contains("@")) {
pid = pid.substring(0, pid.indexOf("@"));
}
return pid;
}
public static void attachAgent() {
try {
System.out.println("PID is " + getPid());
VirtualMachine vm = VirtualMachine.attach(getPid());
Properties props = vm.getSystemProperties();
vm.loadAgent(new File(JavaAgent.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getAbsolutePath());
vm.detach();
} catch (Exception e) {
e.printStackTrace();
}
}
static {
System.loadLibrary("attach");
}
public static void main(String[] args) {
attachAgent();
}
}
班级的第31行是 VirtualMachine vm = VirtualMachine.attach(getPid());
有什么线索吗?谢谢你的时间!
暂无答案!
目前还没有任何答案,快来回答吧!