Java Attach API: UnsatisfiedLinkError

When using the Java Attach API I get the following Linux link error (only for checking on different machines):

 Exception in thread "main" java.lang.UnsatisfiedLinkError: sun.tools.attach.WindowsAttachProvider.tempPath()Ljava/lang/String; at sun.tools.attach.WindowsAttachProvider.tempPath(Native Method) at sun.tools.attach.WindowsAttachProvider.isTempPathSecure(WindowsAttachProvider.java:74) at sun.tools.attach.WindowsAttachProvider.listVirtualMachines(WindowsAttachProvider.java:58) at com.sun.tools.attach.VirtualMachine.list(VirtualMachine.java:134) at sun.tools.jconsole.LocalVirtualMachine.getAttachableVMs(LocalVirtualMachine.java:151) at sun.tools.jconsole.LocalVirtualMachine.getAllVirtualMachines(LocalVirtualMachine.java:110) ... 

Interestingly, on Solaris and Windows, it works out of the box.

I tried several combinations, specifying java.library.path to point to the directory containing libattach.so , but with no luck.

What is wrong here?

And as a bonus question:
Is there any way to see which native library is actually associated with the java class?

+6
source share
1 answer

Different AttachProvider are used on different platforms. On Linux, it should not use sun.tools.attach.WindowsAttachProvider. This is for Windows.

 [solaris] sun.tools.attach.SolarisAttachProvider [windows] sun.tools.attach.WindowsAttachProvider [linux] sun.tools.attach.LinuxAttachProvider 

This is configured in the resource file META-INF \ services \ com.sun.tools.attach.spi.AttachProvider (usually this file exists in tools.jar). It will look for CLASSPATH to get the first occurrence of this resource file and read the AttachProvider implementation class from it.

So, you can solve this problem by searching for sun.tools.attach.WindowsAttachProvider in your CLASSPATH. You may have included tools.jar from Windows.

+6
source

All Articles