agent
Dynamically load a Java Agent or acquire java.lang.instrument.Instrumentation via SPI
- Load a Java Agent - dynamically, without prerequisite JAR file or JVM arguments
- Get hold of an Instrumentation instance with SPI (using only this module as a runtime dependency)
For use in JUnit tests, please see the other module instrumental.agent.junit which already has JUnit 4 Rules and JUnit 5 Extensions.
Examples
Instrumentation via SPI
Instrumentation instrumentation = ServiceLoader.load(Instrumentation.class) .iterator().next();
Dynamically Load an Agent Class
String agentArguments = "arbitrary.arguments=go.here"; Path stubJar = DynamicAgent.loadAgent(StubAgent.class, agentArguments);