public class ByteBuddyAgent extends Object
The Byte Buddy agent provides a JVM Instrumentation
in order to allow Byte Buddy the
redefinition of already loaded classes. An agent must normally be specified via the command line via the
javaagent
parameter. As an argument to this parameter, one must specify the location of this agent's jar
file such as for example in
java -javaagent:byte-buddy-agent.jar -jar app.jar
For JDK installations of the Java virtual machine, an agent can however also be installed after startup using the
Attach API which is contained in the JDK's tools.jar. As instrumentation is commonly used in unit
tests which are normally run on a JDK, the Byte Buddy agent provides a convenience installation method
installOnOpenJDK()
which is only guaranteed to work on the OpenJDK and compatible JDKs.
Note: This class's name is known to the Byte Buddy main application and must not be altered.
Modifier and Type | Class and Description |
---|---|
static class |
ByteBuddyAgent.Installer
An installer class which defined the hook-in methods that are required by the Java agent specification.
|
Modifier and Type | Method and Description |
---|---|
static Instrumentation |
getInstrumentation()
Looks up the
Instrumentation instance of an installed Byte Buddy agent. |
static Instrumentation |
installOnOpenJDK()
Installs the Byte Buddy agent using the tools.jar's Attach API.
|
public static Instrumentation installOnOpenJDK()
Installs the Byte Buddy agent using the tools.jar's Attach API. This installation is only possible on the OpenJDK and compatible JDKs as the tools.jar is not available on non-JDK JVMs or other JDKs. Note that the installation is only performed if the Byte Buddy agent is not yet installed. However, this method implies reflective lookup and reflective invocation such that the returned value should be cached rather than calling this method several times.
Note: If the currently running JVM does not support the runtime installation of an agent, this method
throws an IllegalStateException
Instrumentation
instance that is provided by the Byte Buddy agent.public static Instrumentation getInstrumentation()
Looks up the Instrumentation
instance of an installed Byte Buddy agent. Note that
this method implies reflective lookup and reflective invocation such that the returned value should be cached
rather than calling this method several times.
Note: This method throws an IllegalStateException
If the Byte Buddy agent is not
properly installed.
Instrumentation
instance which is provided by an installed
Byte Buddy agent.Copyright © 2014–2015. All rights reserved.