Any way on starting an agent without the attach libary?

112 views Asked by At

How can I have a Java Agent start without the attach library?

2

There are 2 answers

0
Rafael Winterhalter On

You can add a Java agent when starting a program using the -javaagent:./agent.jar=arg command. The ./agent.jar is the location of the jar file containing the agent code. It is required to add a manifest containing an entry Agent-Premain naming a class containing a premain method.

For a running agent, the tools.jar is required. As an exception, I implemented the attachment protocol for Unix systems for HotSpot in Byte Buddy.

0
Svet On

You can use jattach which implements the important bits for Windows and Linux.

Attaching an agent can be done with: jattach PID load instrument false /path/to/agent.jar`