Java 无法连接到VM:com.sun.tools.attach.AttachNotSupported异常:未安装提供程序
我正试图在正在运行的进程上放置一个java代理。我的问题是我无法连接到VM,因为我遇到以下错误:Java 无法连接到VM:com.sun.tools.attach.AttachNotSupported异常:未安装提供程序,java,instrumentation,javaagents,Java,Instrumentation,Javaagents,我正试图在正在运行的进程上放置一个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:
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:未安装提供程序
这是产生错误的类:
公共类JavaAgent{
公共静态void agentmain(字符串字符串参数、指令插入){
System.out.println(“hi from agentmain”);
}
私有静态字符串getPid(){
RuntimeMXBean=ManagementFactory.getRuntimeMXBean();
字符串pid=bean.getName();
if(pid.contains(“@”)){
pid=pid.substring(0,pid.indexOf(“@”);
}
返回pid;
}
公共静态void attachAgent(){
试一试{
System.out.println(“PID是”+getPid());
VirtualMachine vm=VirtualMachine.attach(getPid());
props props=vm.getSystemProperties();
loadAgent(新文件(JavaAgent.class.getProtectionDomain().getCodeSource().getLocation().Tori().getPath()).getAbsolutePath());
vm.detach();
}捕获(例外e){
e、 printStackTrace();
}
}
静止的{
系统加载库(“附件”);
}
公共静态void main(字符串[]args){
附件();
}
}
类的第31行是VirtualMachine vm=VirtualMachine.attach(getPid())代码>
有什么线索吗?谢谢你的时间 您运行的是JRE而不是JVM的JDK安装吗?不是JDK@RafaelWinterhalterMaybe附加库已经在别处加载了吗?如果您单步执行代码,VM会提供什么答案?