невозможно подключиться к виртуальной машине: com.sun.tools.attach.AttachNotSupportedException: поставщики не установлены - PullRequest
0 голосов
/ 24 января 2020

Я пытаюсь включить агент java в запущенный процесс. Моя проблема заключается в том, что я не могу подключиться к виртуальной машине, потому что я получаю следующую ошибку:

java.util.ServiceConfigurationError: com.sun.tools.attach.spi.AttachProvider: Provider sun.tools.attach.WindowsAttachProvider could not be instantiated
com.sun.tools.attach.AttachNotSupportedException: no providers installed
    at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:203)
    at io.github.giantnuker.tailor.transform.JavaAgent.attachAgent(JavaAgent.java:31)

Важной частью является com.sun.tools.attach.AttachNotSupportedException: no providers installed

Это класс, который выдает ошибку:

public class JavaAgent {
    public static void agentmain(String stringArguments, Instrumentation instrumentation) {
        System.out.println("hi from agentmain");
    }

    private static String getPid() {
        RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
        String pid = bean.getName();
        if (pid.contains("@")) {
            pid = pid.substring(0, pid.indexOf("@"));
        }
        return pid;
    }

    public static void attachAgent() {
        try {
            System.out.println("PID is " + getPid());
            VirtualMachine vm = VirtualMachine.attach(getPid());
            Properties props = vm.getSystemProperties();
            vm.loadAgent(new File(JavaAgent.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getAbsolutePath());
            vm.detach();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    static {
        System.loadLibrary("attach");
    }
    public static void main(String[] args) {
        attachAgent();
    }
}

Строка 31 класса - VirtualMachine vm = VirtualMachine.attach(getPid());

Есть какие-нибудь подсказки? Спасибо за ваше время!

...