Start JaCoCo agent dynamically

63 views
Skip to first unread message

Shehan Dhaleesha

unread,
Oct 22, 2019, 1:27:18 AM10/22/19
to JaCoCo and EclEmma Users
So what I want is start the JaCoCo agent dynamically so that I don't need to give any specific jar program name to start the agent. So this is what I tried.

java -javaagent:jacocoagent.jar -jar myjar.jar

So I used previous command to execute the JaCoCo agent and used the .exec file to generate a coverage report (note that this is not a test coverage report). So what I want now is, starting the agent dynamically, which means, not typing the above command. Is this can be done? If not what should be the way to approach this?

Note that I don't want use any maven or ant plugin in this case.

Marc Hoffmann

unread,
Oct 22, 2019, 3:55:51 AM10/22/19
to jac...@googlegroups.com

Hi,

so you mean attaching the agent to a already running Java program?

This is not possible due to the way how JaCoCo is implemented (adding new members to instrumented classes) and restrictions of the JVM (no schema changes on re-transformation possible).

Regards,
-marc

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/f966a983-62e1-4eb3-bc58-d43e42977197%40googlegroups.com.


Shehan Dhaleesha

unread,
Oct 23, 2019, 1:39:09 AM10/23/19
to JaCoCo and EclEmma Users
So I would like to know how actually jacoco works. This is what I have in my mind now. When the jacoco runs there should be an executable jar file so that jacoco agent can generate the jacoco.exec file. When the jacoco is attached to the test cases within the java project my maven or any avaiable plugin, is the above process happening? Which means there should be some executable jar file to execute the tests and based on that jar file the jacoco.exec is generated. Is this right? If not can you please give me some idea how actually jacoco works?


On Tuesday, October 22, 2019 at 1:25:51 PM UTC+5:30, Marc R. Hoffmann wrote:

Hi,

so you mean attaching the agent to a already running Java program?

This is not possible due to the way how JaCoCo is implemented (adding new members to instrumented classes) and restrictions of the JVM (no schema changes on re-transformation possible).

Regards,
-marc



On 2019-10-22 07:27, Shehan Dhaleesha wrote:

So what I want is start the JaCoCo agent dynamically so that I don't need to give any specific jar program name to start the agent. So this is what I tried.

java -javaagent:jacocoagent.jar -jar myjar.jar

So I used previous command to execute the JaCoCo agent and used the .exec file to generate a coverage report (note that this is not a test coverage report). So what I want now is, starting the agent dynamically, which means, not typing the above command. Is this can be done? If not what should be the way to approach this?

Note that I don't want use any maven or ant plugin in this case.


--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jac...@googlegroups.com.

Marc Hoffmann

unread,
Oct 23, 2019, 4:07:29 AM10/23/19
to JaCoCo and EclEmma Users
Hi,

the JaCoCo agent records execution data for any class executed by the JVM (except bootstrap classes, typically the JDK classes itself). No need to have a “executable jar”, also classpath oder modulepath will work.

Regards,
-marc


To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/a59bda25-1968-44f8-88a4-352ae6269f97%40googlegroups.com.

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages