7

I have to write a .sh launching an UI application covered with Jacoco. On exit, a jacoco report must be generated.

I'm not able to generate the jacoco.exec with this simple command :

java -jar ../binaries/editor.debug/application.jar -javaagent:/atgl/products/jacoco/0.6.3/lib/jacocoagent.jar=destfile=jacoco.exec

The first part of the command works fine and launch the program, but the -javaagent option doesn't generate report and the program doesn't launch. If I do a syntax error it's exactly the same behavior.

What's wrong with my command ?

Secondly, this command create a .exec file. How can I generate a .html report in command line ?

4 Answers 4

5

The problem was the position of the -javaagent option. It needed to be in first position, like this :

java -javaagent:/atgl/products/jacoco/0.6.3/lib/jacocoagent.jar=destfile=jacoco.exec -jar ../binaries/editor.debug/application.jar

Then as Godin said, it's not possible to generate report in command line. I created an ant file exectoreport.xml with a rule do_jacoco_reports. The rule is launched by a script exectoreport.sh, that must be called after the natural exit of the application.

Sign up to request clarification or add additional context in comments.

Comments

5

By using jacococli.jar from jacoco 0.7.9 version, now reports can be generated using command line. I was trying the same and able to generate the report using commandline. If you are able to generate jacoco.exec file successfully use below command to generate the report.

java -jar "your local path/jacococli.jar" report "your local path/jacoco.exec" --classfiles "project path to class files" --html "local path\jacoco-report" --name myReport --sourcefiles "project path\src\main\java"

You should be able to see report in html format. Reference http://www.jacoco.org/jacoco/trunk/doc/cli.html

4 Comments

How did you get jacococli.jar file? I added as dependencies in pom.xml but it did not generate anything for me.
I downloaded the jar and got that added in my enterprise nexus repo.
To where should the --classfiles option direct to?
Its long since I worked on this but it should point to build folder where class file exists for the project
3

Usage of JaCoCo involves two steps - gathering of coverage information and generation of report. So nothing wrong with your command - it gathers coverage information into .exec file. After this you can generate report using Ant or Maven, or built your own report generator using JaCoCo APIs - JaCoCo does not yet provide a out-of-the-box command line interface for report generation, however there is an example of API usage for report generation.

Update (2/8/2019)

JaCoCo provides command line interface since version 0.8.0.

2 Comments

Thanks for your answer. But I can't even generate a .exec file ! Need I to compile my application in a special way to instrument it before executing it with jacoco agent ? I think I will use ant to generate the report once I have the .exec file
Precision : the .exec file si generated when I enter -javaagent:/atgl/products/jacoco/0.6.3/lib/jacocoagent.jar=destfile=jacoco.exec in the VM argument field in eclipse. It doesn't work on command line
0

if you have added jacoco plugins into your pom.xml then simply run this command and you will see jacoco report inside target\site\jacoco

mvn jacoco:report

To add jacoco plugin into your pom.xml, paste below code snippet:

<plugins>
    <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.2</version>
        <executions>
            <execution>
                <goals>
                    <goal>prepare-agent</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.