标签: attach-api

使用Attach Api时出错

在Eclipse中使用attach API时会在控制台中引发错误.

为了使用attach API,我在eclipse中安装了JRE,然后在当前JRE的外部jar选项中使用了包含tools.jar的edit选项.

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

java.lang.UnsatisfiedLinkError:java.library.path中没有附件com.sun.tools.attach.AttachNotSupportedException:在dynamicLoadingTest.VMAttach的com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:190)上没有安装任何提供程序.主要(VMAttach.java:17)

这是执行的简单程序.import 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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

提到的进程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)
Run Code Online (Sandbox Code Playgroud)

java instrumentation agent attach-api

9
推荐指数
1
解决办法
4126
查看次数

在Java 9中以编程方式连接到JMX代理

我需要连接到编程方式使用(如果有必要在运行时加载剂)附加API JMX剂如实例这里.这在Java 8中运行良好,但在Java 9中不起作用,因为lib文件夹中不再有management-agent.jar:

String agent = vm.getSystemProperties().getProperty("java.home") +
   File.separator + "lib" + File.separator + "management-agent.jar";
Run Code Online (Sandbox Code Playgroud)

能否请您在Java 9中建议什么是正确的方法?

在此先感谢,瓦迪姆

java jmx attach-api java-9

3
推荐指数
1
解决办法
529
查看次数

标签 统计

attach-api ×2

java ×2

agent ×1

instrumentation ×1

java-9 ×1

jmx ×1