在Eclipse中使用attach API时会在控制台中引发错误.
为了使用attach API,我在eclipse中安装了JRE,然后在当前JRE的外部jar选项中使用了包含tools.jar的edit选项.
但是当我尝试执行一个简单的程序时,它会抛出以下错误
java.lang.UnsatisfiedLinkError:java.library.path中没有附件com.sun.tools.attach.AttachNotSupportedException:在dynamicLoadingTest.VMAttach的com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:190)上没有安装任何提供程序.主要(VMAttach.java:17)
这是执行的简单程序.import java.io.IOException;
import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;
public class VMAttach {
public static void main(String[] args) {
try {
VirtualMachine vm = VirtualMachine.attach("6832");
} catch (AttachNotSupportedException e) {
System.out.println("This error");
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
提到的进程ID 6832是在系统上运行的Java应用程序
在将安装的jre更改为jdk后,会产生以下错误
Exception in thread "main" com.sun.tools.attach.AttachNotSupportedException: jvm.dll not loaded by target process
at sun.tools.attach.WindowsVirtualMachine.<init>(WindowsVirtualMachine.java:46)
at sun.tools.attach.WindowsAttachProvider.attachVirtualMachine(WindowsAttachProvider.java:52)
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:195)
at dynamicLoadingTest.VMAttach.main(VMAttach.java:17)
Run Code Online (Sandbox Code Playgroud) 我需要连接到编程方式使用(如果有必要在运行时加载剂)附加API JMX剂如实例这里.这在Java 8中运行良好,但在Java 9中不起作用,因为lib文件夹中不再有management-agent.jar:
String agent = vm.getSystemProperties().getProperty("java.home") +
File.separator + "lib" + File.separator + "management-agent.jar";
Run Code Online (Sandbox Code Playgroud)
能否请您在Java 9中建议什么是正确的方法?
在此先感谢,瓦迪姆