Java Attach API: UnsatisfiedLinkError



当使用Java Attach API时,我只在Linux(在不同的机器上尝试过)上得到以下链接错误:

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)
        ...
有趣的是,在Solaris和Windows上,是开箱运行的。

我尝试了几种指定java.library.path的组合来指向包含libattach.so的目录,但没有成功。

怎么了?

作为附加问题:
是否有一种方法可以查看哪个本机库实际上绑定到java类?

不同的平台使用不同的AttachProvider。在Linux上,它不应该使用sun.tools.attach.WindowsAttachProvider。

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

这是在资源文件META-INFservicescom.sun.tools.attach.spi中配置的。AttachProvider(通常这个文件存在于tools.jar中)。它将搜索CLASSPATH以获得该资源文件的第一次出现,并从中读取AttachProvider实现类。

所以你可以通过在CLASSPATH中搜索sun.tools.attach.WindowsAttachProvider来解决这个问题。

最新更新