簡體   English   中英

附加錯誤從哪里來?

[英]From where does the Attaching Error come?

當我執行我的 Attacher 時,我會得到一個錯誤,我不知道為什么(這些類就像他們應該的那樣)

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 me.paul.TestInjector.Util.attach(Util.java:42)
        at me.paul.TestInjector.Main.main(Main.java:17)

Util 中的第 42 行: VirtualMachine virtualMachine = VirtualMachine.attach(pid); Main 中的第 17 行(方法附加被執行) Util.attach(pid, file);

附加方法:

public static void attach(String pid, File input) {
    System.setProperty("java.libary.path", System.getProperty("java.home").replace("jre", "jdk") + "\\jre\\bin");

    try {
        Field field = ClassLoader.class.getDeclaredField("sys_paths");
        field.setAccessible(true);
        field.set(null, null);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
        return;
    }

    File agentFile = new File(System.getProperty("user.home") + "/Desktop", "agent.jar");

    buildAgent(input, agentFile);

    try {
        VirtualMachine virtualMachine = VirtualMachine.attach(pid);

        virtualMachine.loadAgent(agentFile.getAbsolutePath());
        System.out.println("[Test-Injection] Agent loaded");

        virtualMachine.detach();
        System.out.println("[Test-Injection] detached!");
    } catch (IOException | AttachNotSupportedException | AgentLoadException | AgentInitializationException e) {
        e.printStackTrace();
    }
}

沒有安裝提供者僅僅意味着當前的虛擬機不支持附件。 這通常發生在 JRE(Java 8 和更早版本)上,或者如果檢測模塊不存在(Java 9 和更高版本)。

暫無
暫無

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

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