public static boolean loadAgent ( URL agentJarURL ) throws Exception { File toolsJarFile = findToolsJar ( ) ; Class < ? > vmClass = null ; if ( toolsJarFile == null || ! toolsJarFile . exists ( ) ) { // likely Java 9+ (when tools.jar is not available). Java // 9 also requires that // -Djvm.options=jdk.attach.allowAttachSelf=true is set. vmClass = ClassLoader . getSystemClassLoader ( ) . loadClass ( "com.sun.tools.attach.VirtualMachine" ) ; } else { vmClass = loadVirtualMachine ( toolsJarFile ) ; } if ( vmClass == null ) { return false ; } attachAgent ( vmClass , agentJarURL ) ; return true ; }
Loads agent from the given URL .