Running application with war file compile with clover

I want to know that can we run a war (or sar) file compiled with clover on jBoss and if we can, then does clover provide the facility to check the code coverage.

Say we compile an application with clover and deploy it on server. End users work this application and at the end of the day we want to check how much code was covered during this period. Can we do it?

If we can do it then please mention the configuration steps so that we can check the code coverage.

Please note that this question is from end user's perspective who is using the application and not from jUnit perspective.



3 answers

1 accepted

0 vote

Can anyone please provide a sample target clover.setup for instrumenting the code which is ready to use with tutorial project.

The build_completed.xml file in tutorial contains complete Clover configuration. Just type:

ant clover.all

0 vote

Hi Sumeet,

Yes, Clover can instrument WAR and SAR applications too. Typical steps are as follows:

  • instrument code using <clover-setup> or <clover-instr>; use "threaded" or "interval" flush policy in case when code will be deployed to an application server
  • package instrumented classes into JAR/WAR/SAR/EAR
  • put clover.jar into server's /lib directory (alternatively: bundle clover.jar in the application's jar)
  • deploy instrumented application + clover.db created during instrumentation (use -Dclover.initstring=/path/to/clover.db JVM option to point to the database file)
  • after tests are finished, take clover.db and coverage data files and generate a report using <clover-setup> task



&lt;project name="money_demo" default="code.compile" basedir="."&gt;
    &lt;property name="src" location="src/main/java"/&gt;
    &lt;property name="test.src" location="src/test/java"/&gt;
    &lt;property name="" location="build/app"/&gt;
    &lt;property name="" location="build/test"/&gt;
    &lt;property name="test.result" location="build/testresult"/&gt;
    &lt;property name="junit.jar" location="lib/junit-3.8.2.jar"/&gt;
    &lt;property name="clover.jar" location="../lib/clover.jar"/&gt;
    &lt;taskdef resource="cloverlib.xml" classpath="${clover.jar}"/&gt;
    &lt;path id="build.classpath"&gt;
        &lt;pathelement path="${clover.jar}"/&gt; &lt;!-- I added this to make clover.jar avail in runtime --&gt;
        &lt;pathelement location="${junit.jar}"/&gt;
        &lt;pathelement location="${}"/&gt;
    &lt;path id="testbuild.classpath"&gt;
        &lt;path refid="build.classpath"/&gt;
        &lt;pathelement location="${}"/&gt;
    &lt;target name="-check.clover"&gt;
        &lt;available property="clover.installed" classname="com.cenqua.clover.CloverInstr" /&gt;
    &lt;target name="guard.noclover" depends="-check.clover" unless="clover.installed"&gt;
        &lt;fail message="The target you are attempting to run requires Clover, which doesn't appear to be installed"/&gt;
    &lt;target name=""&gt;
        &lt;clover-html-report outdir="clover_html" title="Clover Demo"/&gt;
    &lt;target name="record.point"&gt;
        &lt;clover-historypoint historyDir="clover_history"/&gt;
    &lt;target name="code.compile"
            description="Creates ${} directory and compiles sources from ${src} to ${}"&gt;
        &lt;mkdir dir="${}"/&gt;
        &lt;javac includeantruntime="false" srcdir="${src}" destdir="${}" classpathref="build.classpath" source="1.4"/&gt;
    &lt;target name="test.compile" depends="code.compile"
            description="Creates ${} directory and compiles sources from ${test.src} to ${}"&gt;
        &lt;mkdir dir="${}"/&gt;
        &lt;javac includeantruntime="false"
               classpathref="testbuild.classpath" source="1.5"/&gt;
    &lt;target name="" depends="test.compile" description="Runs the tests"&gt;
        &lt;mkdir dir="${test.result}"/&gt;
        &lt;junit fork="yes" printsummary="true" showoutput="true"&gt;
            &lt;classpath refid="testbuild.classpath"/&gt;
            &lt;formatter type="xml"/&gt;
            &lt;batchtest fork="yes" todir="${test.result}"&gt;
                &lt;fileset dir="${test.src}" includes="**/*"/&gt;
    &lt;target name="clean"&gt;
        &lt;delete dir="build"/&gt;
        &lt;clover-clean/&gt; &lt;!-- I added this to delete clover database when clean target is executed --&gt;
    &lt;target name="with.clover"&gt;
&lt;target name=""&gt;
           &lt;historical outfile="historical.pdf"
           &lt;format type="pdf"/&gt;
&lt;target name="clover.check" depends="with.clover"&gt;
    &lt;clover-check target="80%"/&gt;
&lt;target name="clover.setup" if="clover.enabled"&gt;
        &lt;mkdir dir="${clover.db.dir}" /&gt;
        &lt;mkdir dir="${clover.instr.dir}" /&gt;
        &lt;clover-instr initString="${clover.db.dir}/coverage.db" destdir="${clover.instr.dir}"&gt;
            &lt;fileset dir="${src}" /&gt;
            &lt;testsources dir="${tests}" /&gt;
            Clover is enabled and will be used for generating test reports

I've added the above mentioned lines (in bold) in the tutorial project and tried the following command ant with.clover clover.setup but nothing happened; not even echo.
Could you please tell me what else do I need to do to make the code compile so that its war could be run on jBoss?

<target name="clover.setup">


Clover is enabled and will be used for generating test reports


<mkdir dir="${clover.db.dir}" />

<mkdir dir="${clover.instr.dir}" />

<clover-instr initString="${clover.db.dir}/coverage.db" destdir="${clover.instr.dir}">

<fileset dir="${src}" />

<testsources dir="${tests}" />




Ran the ant build with a slight change in the clover.setup and this time the new directories were created but they are empty.

I was expecting instrumented classes in those directories but it is not.

Can anyone please provide a sample target clover.setup for instrumenting the code which is ready to use with tutorial project.

The build.xml file defined by you contains both <clover-setup> and <clover-instr> tasks. Both tasks are making virtually the same - they instrument the code - but the difference is that <clover-instr> puts instrumented sources into a specified directory, while the <clover-setup> peforms instrumentation "on the fly", by intercepting the <javac> task.

It means that there is no need to have both tasks defined. I recommend using <clover-setup> only. Similarly the 'ant with.clover clover.setup' call was also incorrect, as no compilation (javac) was triggered.

Please try the following:

* remove <target name="clover.setup"> as it is obsolete

* run 'ant clean with.clover' - it shold enable Clover, compile the code, run tests and generate an HTML report

Hi, I am instrumenmting clover with war file using Ant. I see clover related jar and class files when I see war info. This ensures me that clover instrumented war is correct. I am trying to run soapUI tests and generate coverage files. I have corretcly set up path for clover.db in initstring. However, the coverage files are not generated when soapUI tests are run.

I did similar setup using maven and it worked flawlessly. What could be the issue with ant setup ?

How do you run your soapUI tests exactly?

Do you deploy your application to some server or instantiate container on-the-fly?

If yes, then do you shutdown this sever after tests are finished? By default, Clover's coverage recorders will write coverage files to disk at the JVM shutdown (they attach to proper hook).

If not, then did you set the <clover-setup flushpolicy="treaded"> or <clover-setup flushpolicy="interval">? This will change the default flush policy and start writing coverage files periodically, so there's no need to shutdown JVM.

Do you see the clover.db.liverec file when running your tests? This indicates that at least one coverage recorder has started.

Do you see any Clover-related error messages when running your application? For instance, that the coverage recorder could not start because it did not find the database. This may indicate a problem with initstring. Using runtime property -Dclover.initstring=/path/to/clover.db may help.

Do you see any NoClassDefFound exceptions in the log? Especially the ones with classes from the com_cenqua_clover package? This may indicate that the clover.jar packaged into your WAR was not picked up by a class loader. In such case, putting clover.jar into application server's /lib directory should help.

Hello Marek. Thank you for your quick response.

I deploy the application war file to Glassfish server. Then I run my soapUI tests by giving the Glassfish server end point address in soapUI (ex: xyz.xx.xy.xz:8080/service).

Intially I noticed error in log files: clover database not found at specified path. Executing with -Dclover.initstring=/path/to/clover.db helped to solve this error.

I also added flushpolicy and flush interval attributes in <clover-setup>. Now I see permission denied error:

[#|2014-05-14T12:04:26.582-0400|SEVERE|glassfish3.1.2||_ThreadID=817;_ThreadName=Thread-2;|ERROR: flushing coverage for recorder /home/user/workspace/cloverDB/clover.dbao50rb_hv6t1omy: /home/user/workspace/cloverDB/clover.dbao50rb_hv6t1omy (Permission denied)|#]

In above error, /home/user/workspace/cloverDB/ is the path I specified in initstring, where clover.db present.

I tried changing permission of clover.db, but it didnt help.

Clover did produce the coverage files when I did not use flush policy and stopped the server. So I think my problem was with clover.db path when initially it did not generate files.

Thank you for all your help.

Could you also change a permission for the directory:


to allow Glassfish to create new files in it?

Thanks Marek, changing permission on directory helped.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

86 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you