Java Attach API: UnsatisfiedLinkError
Asked Answered
M

1

6

When using the Java Attach API, I'm getting the following link error on Linux (tried it on different machines) only:

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's working out of the box.

I tried out several combinations of specifying java.library.path to point to the directory which contains the libattach.so but with no luck.

What's wrong here?

And as a bonus question:
Is there a way to see which native library is actually bound to a java class?

Malfeasance answered 8/3, 2013 at 9:20 Comment(5)
Could you find this library in LD_LIBRARY_PATH?Lethe
I also tried it adding to the LD_LIBRARY_PATH - but it hasn't helped. And on Solaris it's also not on the LD_LIBRARY_PATH but it's working here.Malfeasance
It seems that the library is incompatible with the Java class you used. Are they from the same JDK? Is there any other library with the same name in LD_LIBRARY_PATH or java.library.path?Lethe
Check your classpath: is it include some JAR's which contains WindowsAttachProvider?Lethe
Your previous comment was great: My application is packaged in a jar which I invoke. However, there was a directory named <name_of_the_jar>_lib (created by eclipse). I was not aware of that this is some sort of magic name which will cause the jvm to also put the jars inside this directory to the classpath. The directory indeed contained a jar of a wrong java version. Deleting that directory helped. Thank you - I wish I could accept your answer.Malfeasance
L
6

Different AttachProvider are used on different platforms. On Linux, it shouldn't use sun.tools.attach.WindowsAttachProvider. It is for Windows.

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

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

So you can probably resolve this problem by search sun.tools.attach.WindowsAttachProvider in your CLASSPATH. Possibly you have included a tools.jar from Windows.

Lethe answered 8/3, 2013 at 10:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.