title: how to use the jcoverage java tool by using ANT in eclipse
body: <p>I wanna prepare jcoverage report for my unit tests by using ANT and eclipse. I'm using </p>
  
  <ul>
  <li>Apache Ant(TM) version 1.8.3 compiled on February 26 2012</li>
  <li>selenium-server-standalone-2.20.0</li>
  <li>junit-4.8.1.jar</li>
  <li>eclipse sdk 3.6.1</li>
  </ul>
  
  <p>i tried as mentioned in this <a href="http://flylib.com/books/en/1.214.1.136/1/" rel="nofollow">link here</a>.</p>
  
  <p>but i'm not able to succeed.please provide if any documents are available or make me clear how to prepare report.</p>
  
  <p>my ant file:</p>
  
  <pre><code> &lt;?xml version="1.0"?&gt;
  
  &lt;!DOCTYPE project [
     &lt;!ENTITY start_stop_selenium SYSTEM "start_stop_selenium.xml"&gt;
     &lt;!ENTITY properties_build_clean_compile_report SYSTEM  "properties_build_clean_compile_report.xml"&gt;
  ]&gt;
  
  &lt;project name="Run Selenium Tests" default="all_selenium_tests" basedir="."&gt;
  
          &lt;property name="libs" location="lib" /&gt;
          &lt;property name="build.dir" value="${basedir}/build/"/&gt; 
          &lt;property name="build.classes.dir" value="${build.dir}/classes"/&gt; 
          &lt;property name="build.test-classes.dir" value="${build.dir}/test-classes"/&gt; 
          &lt;property name="build.instrumented-classes.dir"  value="${build.dir}/instrumented-classes"/&gt; 
          &lt;property name="build.coverage.dir" value="${build.dir}/coverage"/&gt; 
          &lt;property name="build.reports.dir" value="${build.dir}/reports"/&gt; 
          &lt;property name="lib.dir" value="lib"/&gt; 
          &lt;property name="src" value="src"/&gt; 
          &lt;property name="src.dir" value="${basedir}/src/java"/&gt;  
          &lt;property name="test.dir" value="${basedir}/src/test"/&gt;
  
  
  &lt;!-- Corresponding Jar file for the Jcoverage.--&gt;
          &lt;path id="jcoverage.path"&gt; 
              &lt;fileset dir="${lib.dir}"&gt; 
                  &lt;include name="jcoverage-1.0.5.jar"/&gt; 
                  &lt;include name="log4j-1.2.9.jar"/&gt; 
                  &lt;include name="bcel-5.1.jar"/&gt; 
                  &lt;include name="jakarta-oro-2.0.7.jar"/&gt; 
                  &lt;include name="java-getopt-1.0.9.jar"/&gt; 
              &lt;/fileset&gt; 
          &lt;/path&gt; 
  
     &lt;path id="junit.class.path"&gt;
       &lt;fileset dir="${lib.dir}"&gt;
          &lt;include name="ant-junit.jar"/&gt;
          &lt;include name="jcoverage-1.0.5.jar"/&gt; 
          &lt;include name="log4j-1.2.9.jar"/&gt; 
          &lt;include name="bcel-5.1.jar"/&gt; 
          &lt;include name="jakarta-oro-2.0.7.jar"/&gt; 
          &lt;include name="java-getopt-1.0.9.jar"/&gt; 
          &lt;include name="junit-4.8.1.jar"/&gt;
          &lt;include name="selenium-server-standalone-2.20.0.jar"/&gt; 
          &lt;include name="jetty-repacked-7.6.1.jar"/&gt; 
          &lt;include name="org.mortbay.jetty-6.0.0alpha2.jar"/&gt; 
          &lt;include name="httpclient-4.1.2.jar"/&gt;
          &lt;include name="httpcore-4.1.3.jar"/&gt;
          &lt;include name="httpmime-4.1.2.jar"/&gt;
          &lt;include name="selenium-java-2.20.0.jar"/&gt;
          &lt;include name="selenium-java-2.20.0-srcs.jar"/&gt;
          &lt;include name="logging-selenium-1.2.jar"/&gt;
          &lt;include name="poi-3.7-20101029.jar"/&gt;
          &lt;include name="robotframework-2.5.4.1.jar"/&gt;
          &lt;include name="saxon-8.7.jar"/&gt;
          &lt;include name="jxl.jar"/&gt;
      &lt;/fileset&gt;
    &lt;/path&gt;
  
  
          &lt;target name="init"&gt; 
  
              &lt;!-- &lt;delete dir="${build.dir}"/&gt;
               &lt;delete dir="${build.classes.dir}"/&gt;
               &lt;delete dir="{build.test-classes.dir}"/&gt;
               &lt;delete dir="${build.coverage.dir}"/&gt;
               &lt;delete dir="${build.instrumented-classes.dir}"/&gt;
               &lt;delete dir="${build.reports.dir}"/&gt; --&gt;
  
              &lt;delete dir="${build.dir}"/&gt;
              &lt;mkdir dir="${build.dir}"/&gt; 
              &lt;mkdir dir="${build.classes.dir}"/&gt; 
              &lt;mkdir dir="${build.test-classes.dir}"/&gt; 
              &lt;mkdir dir="${build.coverage.dir}"/&gt; 
              &lt;mkdir dir="${build.instrumented-classes.dir}"/&gt;
              &lt;mkdir dir="${build.reports.dir}"/&gt; 
          &lt;/target&gt;
  
          &lt;target name="compile" description="compile all classes"&gt; 
                  &lt;javac srcdir="${src.dir}" destdir="${build.classes.dir}" failonerror="yes" debug="yes"&gt; 
                  &lt;/javac&gt;
          &lt;/target&gt;
  
          &lt;target name="instrument" description="Add jcoverage instrumentation"&gt; 
              &lt;instrument todir = "${build.instrumented-classes.dir}"&gt; 
              &lt;ignore regex="org.apache.log4j.*"/&gt; 
              &lt;fileset dir="${build.classes.dir}"&gt; 
              &lt;include name="**/*.class"/&gt; 
              &lt;/fileset&gt; 
              &lt;/instrument&gt;
          &lt;/target&gt;
  
  
              &lt;target name="test" description="Unit test the application"&gt; 
                  &lt;javac srcdir="${test.dir}" destdir="${build.test-classes.dir}" failonerror="yes" debug="yes"&gt; 
                  &lt;classpath refid="junit.class.path"/&gt; 
  
                  &lt;classpath location="${build.classes.dir}"/&gt; 
                  &lt;/javac&gt;
                  &lt;junit fork="yes" dir="${basedir}" errorProperty="test.failed" failureProperty="test.failed"&gt; 
  
            &lt;!-- note the classpath order, instrumented classes are before the original (uninstrumented) classes. --&gt;
  
                  &lt;classpath refid="junit.class.path"/&gt;
                  &lt;classpath location="${build.instrumented-classes.dir}"/&gt; 
                  &lt;classpath location="${build.classes.dir}"/&gt; 
                  &lt;classpath location="${build.test-classes.dir}"/&gt; 
  
             &lt;!-- the instrumented classes reference classes used by the jcoverage runtime. --&gt; 
  
             &lt;classpath refid="jcoverage.path"/&gt; 
             &lt;formatter type="xml"/&gt;  
  
             &lt;batchtest todir="${build.reports.dir}" &gt; 
             &lt;fileset dir="${build.test-classes.dir}"&gt; 
             &lt;include name="**/*Test.class"/&gt; 
             &lt;/fileset&gt; 
             &lt;/batchtest&gt; 
             &lt;/junit&gt; 
             &lt;/target&gt;
  
  
      &lt;taskdef classpathref="jcoverage.path" resource="tasks.properties"/&gt;
  
            &lt;target name="coverage" description="HTML and XML coverage reports can be found in build/coverage"&gt; 
                  &lt;report srcdir="${src.dir}" destdir="${build.coverage.dir}"/&gt; 
                  &lt;report srcdir="${src.dir}" destdir="${build.coverage.dir}" format="xml"/&gt;  
                  &lt;echo&gt; jcoverage reports have been generated. The HTML report is ${build.coverage.dir}/index.html The XML report is ${build.coverage.dir}/coverage.xml &lt;/echo&gt; 
            &lt;/target&gt;
  
  
    &lt;target name="all_selenium_tests" description="The Main Target for running all tests"&gt;
          &lt;antcall target="init"/&gt;
          &lt;antcall target="compile"/&gt;
          &lt;antcall target="instrument"/&gt; 
          &lt;antcall target="test"/&gt;
          &lt;antcall target="coverage"/&gt;
   &lt;/target&gt; 
  &lt;/project&gt;
  </code></pre>
  
  <p>my junit class:</p>
  
  <pre><code>import org.junit.Before;
  import org.junit.Test;
  import org.openqa.selenium.server.SeleniumServer;
  
  import com.thoughtworks.selenium.DefaultSelenium;
  import com.thoughtworks.selenium.SeleneseTestCase;
  import com.thoughtworks.selenium.Selenium;
  
  
  public class sample extends SeleneseTestCase {
  static Selenium selenium;
  @Before
  public void setUp() throws Exception {
  
        SeleniumServer seleniumserver=new SeleniumServer();
         seleniumserver.boot();
         seleniumserver.start();
         selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com");
         selenium.start();        
  
  }
  
  @Test
  public void testjcoverage() throws Exception{
  
  selenium.windowMaximize();
  selenium.windowFocus();
  
  selenium.setSpeed("1000");
  
  selenium.open("/results-web/results/authentication/public/login?");
  
  
  selenium.type("id=USER","labcorp" );
  selenium.type("id=PASSWORD","Labcorp" );
  selenium.click("css=input.loginButton");
  
  selenium.stop();
  }
  }
  </code></pre>
  
  <p>console error:  </p>
  
  <pre><code>Buildfile: E:\jcoverage\jcoverage\refactored-param-build.xml
  [taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
  all_selenium_tests:
  [taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
  init:
  [taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
  compiling:
  [taskdef] Could not load definitions from resource $(lib.dir). It could not be found.
  instrument:
  
  BUILD FAILED
  E:\jcoverage\jcoverage\refactored-param-build.xml:25: The following error occurred while executing this line:
  E:\jcoverage\jcoverage\refactored-param-build.xml:96: Problem: failed to create task or type instrument
  Cause: The name is undefined.
  Action: Check the spelling.
  Action: Check that any custom tasks/types have been declared.
  Action: Check that any &lt;presetdef&gt;/&lt;macrodef&gt; declarations have taken place.
  
  
  Total time: 125 milliseconds
  </code></pre>
  
  <p>please provide a solution.</p>