如果你能得到的虛擬機,你的目標,你可以將使用
com.sun.tools.attach.VirtualMachine
例如,如果你有PID你代理的ProcessID ,你的JAR的目標是處理JAR的路徑和裝載機你可以嘗試這樣的事:
private static void attach(String pid, String jarPath,
ClassLoader toolLoader) throws Exception {
Class<?> attacherLib = toolLoader.loadClass("com.sun.tools.attach.VirtualMachine");
Class<?> string = toolLoader.loadClass("java.lang.String");
Method attach = attacherLib.getMethod("attach", string);
Object instance = attach.invoke(null, pid);
Method loadAgent = attacherLib.getMethod("loadAgent", string, string);
loadAgent.invoke(instance, jarFilePath, "");
Method detach = attacherLib.getMethod("detach");
detach.invoke(instance);
}
讓我知道,如果是明確的,或者您需要其他幫助。