Files
JuiceAgent/tests/src/AddToClassLoader.java
T
xiaozhou233 6bf2d31798 Feat: add IntelliJ integration tests for native API
- 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
2026-08-17 00:16:24 +08:00

31 lines
935 B
Java

import cn.xiaozhou233.juiceagent.api.JuiceAgent;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
public class AddToClassLoader {
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
System.load(new File("resources/libagent.dll").getAbsolutePath());
JuiceAgent.init("");
ClassLoader cl = new ClassLoader(){};
invokeTest(cl);
JuiceAgent.addToClassLoader(new File("Injection.jar").getAbsolutePath(), cl);
invokeTest(cl);
}
public static void invokeTest(ClassLoader cl) {
try {
Class<?> clz = cl.loadClass("Injection");
System.out.println("ClassLoader: " + clz.getClassLoader().toString());
clz.getMethod("test").invoke(null);
} catch (Exception e) {
e.printStackTrace();
}
}
}