Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while using Attach Api

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)
like image 324
Sanyam Goel Avatar asked Jan 12 '13 08:01

Sanyam Goel


2 Answers

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

like image 62
Deepak kumar Jha Avatar answered Sep 29 '22 07:09

Deepak kumar Jha


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

like image 33
Evgeni Sergeev Avatar answered Sep 29 '22 07:09

Evgeni Sergeev