簡體   English   中英

在 Java 中使用附加 api

[英]Using the attach api in Java

抱歉,如果這是一個愚蠢的問題,我對 Java 還是很陌生。

I want to use the attach API in Java 14. To my knowledge, that was moved to jdk.attach in Java 9. I ran java --list-modules and I had the module installed.

我如何在我的項目中實際使用該模塊? 我嘗試了import jdk.attach但這引發了錯誤。

我將 JDK14 與模塊定義一起使用,這就是我需要更改才能與我的 module-info.java 一起使用的所有內容:

requires transitive jdk.attach;

這是一個簡單的調用來運行它:

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

...

public static void main(String[] args) throws AttachNotSupportedException, IOException
{
    System.out.println("BEGIN");
    var vms = VirtualMachine.list();
    for (var vm : vms)
    {
        System.out.println("vm="+vm);

    }

    System.out.println("END");
}

上面的代碼在非模塊項目中按原樣運行。

您必須導入com.sun.tools.attach.<className>com.sun.tools.attach.spi.<className> 沒有那么多資源,但是來自 oracle 的這個似乎不錯: https://blogs.ZA189C633D9995E11BF8607170EC9A4B88Z.com/corejavatechtips/the-attach-api

暫無
暫無

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

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