Error while using Attach Api

5.2k views Asked by At

While using attach API in Eclipse error is thrown in console.

In order to use attach API I went to installed JRE in eclipse and then using edit option included the tools.jar in the external jars option in current JRE.

But it throws the following error when i try to execute a simple program such as

java.lang.UnsatisfiedLinkError: no attach in java.library.path com.sun.tools.attach.AttachNotSupportedException: no providers installed at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:190) at dynamicLoadingTest.VMAttach.main(VMAttach.java:17)

This is the simple program executed. 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();
        }
    }
}

The process id mentioned 6832 is of a Java application running on the system

On changing the installed jre to jdk following error is produced

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)
3

There are 3 answers

1
Deepak kumar Jha On BEST ANSWER

Actually, This problem orignates when you have diffrent jdks in your system and all are included on the class path.

0
Evgeni Sergeev On

For me, the solution was to put attach.dll from the JDK (same version as your JRE) into the JRE's bin directory.

0
Sanyam Goel On

I tried the same with JDK1.7 and it is working fine. With JDK1.6 the problem remains .