簡體   English   中英

Java Attach API:UnsatisfiedLinkError

[英]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。 它適用於Windows。

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

這是在資源文件META-INF \\ _服務\\ com.sun.tools.attach.spi.AttachProvider中配置的(通常此文件存在於tools.jar中)。 它將搜索CLASSPATH以首次出現此資源文件,並從中讀取AttachProvider實現類。

因此,您可以通過在CLASSPATH中搜索sun.tools.attach.WindowsAttachProvider來解決此問題。 可能你已經從Windows中包含了tools.jar。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM