java - 无法附加到 VM:com.sun.tools.attach.AttachNotSupportedException:未安装提供程序
问题描述
我正在尝试在正在运行的进程上放置一个 java 代理。我的问题是我无法附加到 VM,因为我收到以下错误:
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());
有什么线索吗?谢谢你的时间!
解决方案
推荐阅读
- r - 使用 purrr::map 循环列表产生错误
- xml - XML 和 DTD 中的 ID 和 IDREF 配置
- php - PHP 使用 Wordpress 数据库和自己的数据库
- javascript - KeyValue 和 AutoComplete 的 Angular 过滤器管道
- python - Pandas - 以类似方式按位计算加权平均值
- regex - 如何在 Firebase 中设计正则表达式?
- spring - Spring Boot 2.1.5:无法用验证消息上的字段名称替换 {0}
- web - 有没有办法在编码之前知道 url 是什么?
- google-sheets - 使用唯一 ID 号链接联系人的公式
- multithreading - 如何并行执行 UFT 脚本?