How to instrument .jar programmatically?

44 views
Skip to first unread message

Charlie Gordon

unread,
May 4, 2020, 9:03:35 AM5/4/20
to JaCoCo and EclEmma Users
Hello, dear developers.

I have a .jar file of the compiler that I want to instrument by passing it one program or another. How can I do this programmatically?

I saw your instrumentation API example "CoreTutorial.java", which instruments, executes and analyzes a single target class. 
But it remains unclear how to do the part related to instrumentation and obtaining the result, 
if you need to execute a command like this programmatically, and preferably not writing the result to a file, but immediately passing it to the report generation module:

java -javaagent:pathToJacocoAgent=destfile=pathToJacocoExec -jar pathToCompiler.jar fileForCompiler

I would be grateful if you would help with this.

Thanks for your work.

Marc Hoffmann

unread,
May 4, 2020, 10:34:32 AM5/4/20
to jac...@googlegroups.com
Hello Charlie,

if you don’t want to write the execution data to a file you can start the agent e.g. in tcpclient mode. This is how for example our coverage launcher in Eclipse works:

1) Start an TCP server on an arbitrary port
2) Programmatically launch the JVM with the parameter -javaagent:pathToJacocoAgent=output=tcspclient,port=<port allocated in step 1>

The agent will connect to the server and send execution data when the JVM shuts down or you can also request dumps at arbitrary points in time.

Our example comes with basic execution data server: https://www.jacoco.org/jacoco/trunk/doc/api.html


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/933ae953-3fd6-4561-8c33-88915cdff814%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages