How do I start my Java program with more than one java agent?
Asked Answered
V

4

102

I'm aware of how to start a java progam with a java agent:

java -javaagent:myAgent.jar MyJavaProgram

But what if I want to add 2 or more java agents to instrument my program? I do not want to reinvoke the java -javaagent:... for every agent I have to load in JVM.

I've tried something like this :

java -javaagent:agentA.jar, agentB.jar MyJavaProgram

or something like this:

java -javaagent:agentA.jar agentB.jar MyJavaProgram

But have no success.

Is there an answer to solve my problem ?

Thank you.

Venezuela answered 16/5, 2009 at 15:44 Comment(0)
P
173

How about two javaagent parameters?

java -javaagent:agentA.jar -javaagent:agentB.jar MyJavaProgram
Paluas answered 16/5, 2009 at 15:50 Comment(0)
C
64

It would appear you can do this by using multiple arguments. From the documentation:

On implementations with a command-line interface, an agent is started by adding this option to the command-line:

-javaagent:jarpath[=options] 

jarpath is the path to the agent JAR file. options is the agent options. This switch may be used multiple times on the same command-line, thus creating multiple agents. More than one agent may use the same jarpath. An agent JAR file must conform to the JAR file specification.

(my emphasis)

Chimera answered 16/5, 2009 at 15:50 Comment(0)
I
2

Adding to the above answers, if you are using ant and want to include <jvmargs /> with more than one jar to -javaagent to start the server, here's how I did it,

build.xml

<target name="blah">
...
    <jvmarg value="-javaagent:${jar1.path}" />
    <jvmarg value="-javaagent:${jar2.path}" />
...
</target>
Inspissate answered 19/1, 2016 at 11:17 Comment(0)
W
1

There is a new project with the goal to support multiple Java agents. Currently it is limited to specific ones.

Agent Bond is a super agent, which wraps and dispatches on several other agents. That way, you only have to install a single agent within your JVM with a single set of configuration data (which contains multiple separate parts).

See https://github.com/fabric8io/agent-bond/blob/master/README.md for details

Worriment answered 27/7, 2017 at 5:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.