Skip to content

Instantly share code, notes, and snippets.

View heipacker's full-sized avatar

heipacker heipacker

View GitHub Profile
private static Instrumentation instrumentation() {
ClassLoader mainAppLoader = ClassLoader.getSystemClassLoader();
try {
Class<?> javaAgentClass = mainAppLoader.loadClass("com.dlmu.agent.AgentTest");
Method method = javaAgentClass.getDeclaredMethod("instrumentation", new Class[0]);
return (Instrumentation) method.invoke(null, new Object[0]);
} catch (Throwable e) {
System.out.println("can not get agent class" + e.getStackTrace());
return null;
}
package com.dlmu.agent;
import java.lang.instrument.Instrumentation;
/**
* Created by fupan on 16-4-2.
*/
public class AgentTest {
private static Instrumentation inst = null;
hey,hey,hey
package com.dlmu.agent.test;
/**
* Created by fupan on 16-4-2.
*/
public class HelloWorld {
public static void main(String[] args) {
System.out.println("hello, world.");
}