Search code examples
javadebuggingjavaagents

Use -javaagent without packaging agent into a jar


Is it possible to run java -javaagent:myagent.jar some.package.Main without having agent packaged to a jar? Something like java agent.MyAgent some.package.Main

I have a source code for an agent and would like to be able to debug it and later change it so it is not needed to use -javaagent at all but instead select some.package.Main to execute through GUI.

BTrace is able to connect to a running process using PID or connect to a process using -javaagent. I'm looking for something similar to first approach (using PID), but so I can start a process from scratch as well.


Solution

  • In Java 6 you can use Attach API to load agent programmatically (without -javaagent), but it still requires agent to be packaged as jar.