Skip to content

Instantly share code, notes, and snippets.

@apangin
Created January 31, 2016 19:00
Show Gist options
  • Save apangin/90950b6b9a25fbdebf63 to your computer and use it in GitHub Desktop.
Save apangin/90950b6b9a25fbdebf63 to your computer and use it in GitHub Desktop.
import com.sun.tools.attach.VirtualMachine;
import java.nio.file.Paths;
public class InjectAgent {
public static void main(String[] args) throws Exception {
String PID = args[0];
String agentJar = Paths.get("retransformer.jar").toAbsolutePath().toString();
VirtualMachine vm = VirtualMachine.attach(PID);
try {
vm.loadAgent(agentJar);
} finally {
vm.detach();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment