Class Attacher

java.lang.Object
net.bytebuddy.agent.Attacher

public class Attacher extends Object
A Java program that attaches a Java agent to an external process.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    The name of the attach method of the VirtualMachine class.
    private static final String
    The name of the detach method of the VirtualMachine class.
    private static final String
    The name of the loadAgent method of the VirtualMachine class.
    private static final String
    The name of the loadAgentPath method of the VirtualMachine class.
    private static final Object
    Base for access to a reflective member to make the code more readable.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    The attacher provides only static utility methods and should not be instantiated.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static void
    install(Class<?> virtualMachineType, String processId, String agent, boolean isNative, String argument)
    Installs a Java agent on a target VM.
    static void
    main(String[] args)
    Runs the attacher as a Java application.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • STATIC_MEMBER

      private static final Object STATIC_MEMBER
      Base for access to a reflective member to make the code more readable.
    • ATTACH_METHOD_NAME

      private static final String ATTACH_METHOD_NAME
      The name of the attach method of the VirtualMachine class.
      See Also:
    • LOAD_AGENT_METHOD_NAME

      private static final String LOAD_AGENT_METHOD_NAME
      The name of the loadAgent method of the VirtualMachine class.
      See Also:
    • LOAD_AGENT_PATH_METHOD_NAME

      private static final String LOAD_AGENT_PATH_METHOD_NAME
      The name of the loadAgentPath method of the VirtualMachine class.
      See Also:
    • DETACH_METHOD_NAME

      private static final String DETACH_METHOD_NAME
      The name of the detach method of the VirtualMachine class.
      See Also:
  • Constructor Details

    • Attacher

      private Attacher()
      The attacher provides only static utility methods and should not be instantiated.
  • Method Details

    • main

      public static void main(String[] args)
      Runs the attacher as a Java application.
      Parameters:
      args - A list containing the fully qualified name of the virtual machine type, the process id, the fully qualified name of the Java agent jar followed by an empty string if the argument to the agent is null or any number of strings where the first argument is proceeded by any single character which is stripped off.
    • install

      protected static void install(Class<?> virtualMachineType, String processId, String agent, boolean isNative, String argument) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
      Installs a Java agent on a target VM.
      Parameters:
      virtualMachineType - The virtual machine type to use for the external attachment.
      processId - The id of the process being target of the external attachment.
      agent - The Java agent to attach.
      isNative - true if the agent is native.
      argument - The argument to provide or null if no argument is provided.
      Throws:
      NoSuchMethodException - If the virtual machine type does not define an expected method.
      InvocationTargetException - If the virtual machine type raises an error.
      IllegalAccessException - If a method of the virtual machine type cannot be accessed.