JaCoCo offline instrumentation of war and JMX download of coverage data from multiple J2EE Server instances without jacoco agent in j2ee server classpath!

36 views
Skip to first unread message

fschulte...@gmail.com

unread,
Mar 19, 2020, 7:40:22 AM3/19/20
to JaCoCo and EclEmma Users
Dear JaCoCo Team,

I'm half the way through the work implementing the target mentioned in the title description.

I'm stuck at the point that I have an instrumented war deployed into J2EE Server (JBoss EAP 7.0) and get the jacoco.exec binary data into C:\jboss\bin\jacoco.exe at shutdown of Jboss Server and can generate a valid report from it. 

Note: I don't use the jacoco agent in the server classpath! This is a requirment as I want a solution without jacoco agent at the target enviroment as I have NO control over the J2EE server and can't put any java agent into the server classpath!

Now I need to move this into an User Acceptance Test Enviroment with multiple JBoss servers and want to "dump" the coverage data. I select JMX as the way to go because I also can not open further ports to the tcpserver of JaCoCo as would come to mind.

I analyser the jacoco code where the JMX is initiliaed an I see the only as java agent parameters this will be done.

Question: Is there another way to get the jacoco instrumented code the information to please have the coverage data ready as JMX bean download?

Many thnks for you help and this greate tool.

Cheers
Frank

Evgeny Mandrikov

unread,
Mar 19, 2020, 8:21:01 AM3/19/20
to JaCoCo and EclEmma Users
Hi,


On Thursday, March 19, 2020 at 12:40:22 PM UTC+1, fschulte...@gmail.com wrote:
Dear JaCoCo Team,

I'm half the way through the work implementing the target mentioned in the title description.

I'm stuck at the point that I have an instrumented war deployed into J2EE Server (JBoss EAP 7.0) and get the jacoco.exec binary data into C:\jboss\bin\jacoco.exe at shutdown of Jboss Server and can generate a valid report from it. 

Note: I don't use the jacoco agent in the server classpath! This is a requirment as I want a solution without jacoco agent at the target enviroment as I have NO control over the J2EE server and can't put any java agent into the server classpath!

I suppose that all of the above means that
instead of on-the-fly instrumentation with "-javaagent" JVM option,
you use offline instrumentation.
And instead of placing "jacocoagent.jar" into server classpath,
you placed it inside of your war - as stated on page https://www.jacoco.org/jacoco/trunk/doc/offline.html about offline instrumentation
"jacocoagent.jar has to be accessible by the instrumented classes".

If so, then

Now I need to move this into an User Acceptance Test Enviroment with multiple JBoss servers and want to "dump" the coverage data. I select JMX as the way to go because I also can not open further ports to the tcpserver of JaCoCo as would come to mind.

I analyser the jacoco code where the JMX is initiliaed an I see the only as java agent parameters this will be done.

Question: Is there another way to get the jacoco instrumented code the information to please have the coverage data ready as JMX bean download?

in case of offline instrumentation, quoting the same page https://www.jacoco.org/jacoco/trunk/doc/offline.html

"In offline mode the JaCoCo runtime can be configured with the same set of properties which are available for the agent, except for the includes/excludes options as the class files are already instrumented. There are two different ways to provide the configuration: Configuration File ... System Properties ..."

So the addition of jacoco-agent.properties into your war with the single line "jmx=true" will enable JMX.
And the addition of another line "output=none" will disable writing to file.

Many thnks for you help and this greate tool.


Regards,
Evgeny

fschulte...@gmail.com

unread,
Mar 20, 2020, 10:58:40 AM3/20/20
to JaCoCo and EclEmma Users
Dear Evgeny,,

this is working and I get coverage data, thanks!

Now I need a hint on re-deploy of my instrumented war file. In either case jmx or tcpserver the resource is still bound and fails the deploy because of this.

How can I instruct jacoco to execute the "shutdown()" method for jmx or tcpserver output mode?

Or is there any other way? A Java Listener that reacts on undeploy to call this shutdown() method?

Today I need to restart the complete j2ee server to accomplish a second deploy. 

In my final solution this is not possible for me.

Thanks for your help!
Frank



Evgeny Mandrikov

unread,
Mar 25, 2020, 6:48:16 PM3/25/20
to JaCoCo and EclEmma Users


On Friday, March 20, 2020 at 3:58:40 PM UTC+1, fschulte...@gmail.com wrote:
Dear Evgeny,,

this is working and I get coverage data, thanks!

Now I need a hint on re-deploy of my instrumented war file. In either case jmx or tcpserver the resource is still bound and fails the deploy because of this.

How can I instruct jacoco to execute the "shutdown()" method for jmx or tcpserver output mode?

Or is there any other way? A Java Listener that reacts on undeploy to call this shutdown() method?

Today I need to restart the complete j2ee server to accomplish a second deploy. 


Such "shutdown" method is not exposed as JaCoCo API as you can see in the documentation at https://www.jacoco.org/jacoco/trunk/doc/api/index.html

However using reflection in implementation of your listener you can do the following:

    Object agent = org.jacoco.agent.rt.RT.getAgent();
    Method shutdownMethod = agent.getClass().getDeclaredMethod("shutdown");
    shutdownMethod.invoke(agent);
    
But I'm not sure that this will be enough, because JaCoCo also registers JVM shutdown hook.
You can try the following modification
Using the following unofficial build


Regards,
Evgeny
Reply all
Reply to author
Forward
0 new messages