private static void attachAgent ( Class < ? > vmClass , URL agentJarURL ) throws Exception { String pid = getPID ( ) ; String agentAbsolutePath = new File ( agentJarURL . toURI ( ) . getSchemeSpecificPart ( ) ) . getAbsolutePath ( ) ; Object vm = getAttachMethod ( vmClass ) . invoke ( null , new Object [ ] { pid } ) ; getLoadAgentMethod ( vmClass ) . invoke ( vm , new Object [ ] { agentAbsolutePath } ) ; getDetachMethod ( vmClass ) . invoke ( vm ) ; }
Attaches jar where this class belongs to the current VirtualMachine as an agent .