【问题标题】:Error while using Attach Api使用附加 API 时出错
【发布时间】:2012-12-26 19:49:03
【问题描述】:

在 Eclipse 中使用附加 API 时,控制台会抛出错误。

为了使用附加 API,我在 eclipse 中安装了 JRE,然后使用编辑选项将 tools.jar 包含在当前 JRE 的外部 jars 选项中。

但是当我尝试执行一个简单的程序时,它会抛出以下错误,例如

java.lang.UnsatisfiedLinkError: java.library.path 中没有附加 com.sun.tools.attach.AttachNotSupportedException:没有提供者 安装在 com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:190) 在 dynamicLoadingTest.VMAttach.main(VMAttach.java:17)

这是执行的简单程序。 导入 java.io.IOException;

import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;

public class VMAttach {


    public static void main(String[] args) {


        try {
            VirtualMachine vm = VirtualMachine.attach("6832");
        } catch (AttachNotSupportedException e) {
            System.out.println("This error");
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

提到的进程id 6832是系统上运行的Java应用程序

在将安装的 jre 更改为 jdk 时会产生以下错误

Exception in thread "main" com.sun.tools.attach.AttachNotSupportedException: jvm.dll not loaded by target process
    at sun.tools.attach.WindowsVirtualMachine.<init>(WindowsVirtualMachine.java:46)
    at sun.tools.attach.WindowsAttachProvider.attachVirtualMachine(WindowsAttachProvider.java:52)
    at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:195)
    at dynamicLoadingTest.VMAttach.main(VMAttach.java:17)

【问题讨论】:

  • 看来你需要重新添加库
  • 是的,这个问题也源于我的系统。
  • @sansix 我又做了一次,但问题仍然存在
  • @SanyamGoel 试试看这个stackoverflow.com/questions/5565356/…
  • @sanix 我已经检查了 java 库路径,它包含 tools.jar 所在的 jdk 库的路径

标签: java instrumentation agent attach-api


【解决方案1】:

对我来说,解决方案是将 JDK(与您的 JRE 版本相同)中的 attach.dll 放入 JRE 的 bin 目录中。

【讨论】:

    【解决方案2】:

    实际上,当您的系统中有不同的 jdk 并且所有 jdk 都包含在类路径中时,就会出现此问题。

    【讨论】:

    • 这个答案可以扩展吗?如何检测和/或解决此问题?
    【解决方案3】:

    我在 JDK1.7 上进行了同样的尝试,它工作正常。 JDK1.6 问题依然存在。

    【讨论】:

      猜你喜欢
      • 2014-11-07
      • 1970-01-01
      • 1970-01-01
      • 2011-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多