mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
- Add test JVM sources (Loop, Target) and API tests (AddToBootstrap/SystemClassLoaderSearch, AddToClassLoader, GetClassByName, GetLoadedClasses) - Add injection module (Injection jar) for classloader tests - Add copy-bin.bat to refresh resources/ from build output - Remove obsolete java-loop/java-system-load tests - Ignore IDE dirs and resources/ build artifacts
35 lines
1.2 KiB
Java
35 lines
1.2 KiB
Java
import java.io.File;
|
|
import cn.xiaozhou233.juiceagent.api.JuiceAgent;
|
|
|
|
public class AddToBootstrapClassLoaderSearch {
|
|
public static void main(String[] args) {
|
|
System.load(new File("resources/libagent.dll").getAbsolutePath());
|
|
JuiceAgent.init("");
|
|
|
|
System.out.println("========= Before =========");
|
|
invokeTest();
|
|
System.out.println("========= After =========");
|
|
JuiceAgent.addToBootstrapClassLoaderSearch(new File("Injection.jar").getAbsolutePath());
|
|
invokeTest();
|
|
System.out.println("========= Done =========");
|
|
|
|
}
|
|
|
|
public static void invokeTest() {
|
|
try {
|
|
Class<?> clazz = Class.forName("Injection");
|
|
ClassLoader loader = clazz.getClassLoader();
|
|
System.out.println("ClassLoader: " + (loader == null ? "BootstrapClassLoader" : loader));
|
|
clazz.getMethod("test").invoke(null);
|
|
} catch (ClassNotFoundException e) {
|
|
System.err.println("Injection class not found: " + e.getMessage());
|
|
|
|
} catch (ReflectiveOperationException e) {
|
|
System.err.println("Invoke failed: " + e.getMessage());
|
|
e.printStackTrace();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|