EclipseでアタッチAPIを使用していると、コンソールでエラーがスローされます。
attach APIを使用するために、EclipseにインストールされたJREに移動し、編集オプションを使用して、現在のJREの外部jarオプションにtools.jarを含めました。
しかし、次のような単純なプログラムを実行しようとすると、次のエラーがスローされます
java.lang.UnsatisfiedLinkError:java.library.pathにアタッチがありませんcom.sun.tools.attach.AttachNotSupportedException:dynamicLoadingTest.VMAttachのcom.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:190)にプロバイダーがインストールされていません.main(VMAttach.java:17)
これは実行される単純なプログラムです。インポート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();
}
}
}
言及されているプロセスID6832は、システム上で実行されている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)