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?

MRalwasser
  • 15,605
  • 15
  • 101
  • 147
  • Could you find this library in LD_LIBRARY_PATH? – longhua Mar 08 '13 at 09:30
  • 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. – MRalwasser Mar 08 '13 at 09:32
  • 1
    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? – longhua Mar 08 '13 at 10:12
  • Check your classpath: is it include some JAR's which contains WindowsAttachProvider? – longhua Mar 08 '13 at 10:30
  • Your previous comment was great: My application is packaged in a jar which I invoke. However, there was a directory named _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. – MRalwasser Mar 08 '13 at 10:39

1 Answers1

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.

longhua
  • 4,142
  • 21
  • 28