Hi Marc,
Thank you for pointing out the error. I changed the jar and put the correct
pat in the classpath element. Now I am getting the following error.
test.coverage:
jacoco:coverage] Enhancing java with coverage
[java] java.lang.NoClassDefFoundError: org/jacoco/examples/parser/Main
[java] Caused by: java.lang.ClassNotFoundException:
org.jacoco.examples.parser.Main
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
[java] at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
[java] Could not find the main class: org.jacoco.examples.parser.Main.
Program will exit.
[java] Exception in thread "main"
[java] Java Result: 1
Here is the module.xml
<html>
<project name="module" xmlns:jacoco="antlib:org.jacoco.ant">
<description>
This is the shared module for Valdi OMS project and its modules
</description>
<property name="build.sysclasspath" value="last" />
<property name="main.dir" value="src/main" />
<property name="test.dir" value="src/test" />
<property name="target.dir" value="target" />
<property name="resources.dir" value="resources" />
<property name="main.src.dir" value="${main.dir}/java" />
<property name="main.resources.dir" value="${main.dir}/resources" />
<property name="test.src.dir" value="${test.dir}/java" />
<property name="test.resources.dir" value="${test.dir}/resources" />
<property name="main.lib.dir" value="${main.dir}/lib" />
<property name="main.optional.lib.dir" value="${main.dir}/lib/optional" />
<property name="main.common.lib.dir" value="../../lib/main" />
<property name="test.lib.dir" value="${test.dir}/lib" />
<property name="test.common.lib.dir" value="../../lib/test" />
<property name="common.lib.dir" value="../../lib" />
<property name="target.classes.dir" value="${target.dir}/classes" />
<property name="main.classes.dir" value="${target.classes.dir}/main" />
<property name="main.instrumented.classes.dir"
value="${target.classes.dir}/instrumented/main" />
<property name="test.classes.dir" value="${target.classes.dir}/test" />
<property name="jar.output.dir" value="${target.dir}" />
<property name="javadoc.input.dir" value="${main.dir}/doc" />
<property name="javadoc.output.dir" value="${target.dir}/doc/api" />
<property name="test.output.dir" value="${target.dir}/test" />
<property name="test.report.dir" value="${target.dir}/test/reports" />
<property name="test.coverage.report.dir"
value="${target.dir}/test/coverage" />
<available file="src/main/java" property="main.java.available" />
<available file="src/main/resources" property="main.resources.available" />
<available file="src/test/java" property="test.java.available" />
<property name="src.dir" location="/src/main/java" />
<property name="result.dir" location="/target" />
<property name="result.classes.dir" location="${result.dir}/classes" />
<property name="result.report.dir" location="${result.dir}/site/jacoco" />
<property name="result.exec.file" location="${result.dir}/jacoco.exec" />
<target name="javadoc">
<description>Default javadoc target</description>
</target>
<target name="clean" description="clean files">
<delete dir="target" />
</target>
<target name="cleanjars" description="clean internal files">
<delete failonerror="false">
<fileset dir="target" includes="*.jar" erroronmissingdir="false" />
</delete>
</target>
<target name="clean.classes" description="Clean the target classes">
<delete dir="${target.classes.dir}" />
</target>
<target name="compile">
<description>Default compile target</description>
<antcall target="compile_main" />
<antcall target="compile_test" />
</target>
<target name="compile_main" if="main.java.available">
<do_compile srcref="main.src.path" classpathref="compile.classpath"
output="${main.classes.dir}" />
</target>
<property name="javac.debug" value="true" />
<property name="javac.args" value="" />
<!-- =============================================================
Custom Exports
================================================================= -->
<target name="export_sources">
<description>Export source code from a module to the staging directory. The
root directory should be the module base.</description>
<copy todir="${release.src.staging.dir}/modules/${ant.project.name}">
<fileset dir="${basedir}">
<exclude name="target" />
<exclude name="target/**/*" />
<exclude name="cobertura.ser" />
</fileset>
</copy>
</target>
<target name="export_binary_src">
<description>Export source code for binaries. This is used for associating
sources with class files rather than being able to build the distribution
from source.</description>
<copy todir="${release.bin_src.staging.dir}" includeEmptyDirs="false">
<fileset dir="${basedir}/${main.src.dir}" />
</copy>
</target>
<target name="export_binaries">
<description>Export files for a binary release (jars, resource, javadocs)
to the staging area.</description>
<copy todir="${release.bin.staging.dir}/doc/${ant.project.name}"
includeEmptyDirs="false">
<fileset dir="${target.dir}">
<include name="doc/**/*" />
</fileset>
</copy>
<copy todir="${release.bin.staging.dir}/lib/Internal"
includeEmptyDirs="false">
<fileset dir="${target.dir}">
<include name="*.jar" />
</fileset>
</copy>
<copy todir="${release.bin.staging.dir}/lib/External"
includeEmptyDirs="false">
<fileset dir="${main.lib.dir}">
<include name="*.jar" />
</fileset>
</copy>
<copy todir="${release.bin.staging.dir}/resources" includeEmptyDirs="false">
<fileset dir="${resources.dir}" includes="**/*" />
</copy>
</target>
<target name="export_test_results" if="run.tests">
<description>Export all the test results into a single location to create a
single report</description>
<copy todir="${release.testresults.staging.dir}/junit"
includeEmptyDirs="false">
<fileset dir="${test.output.dir}/junit">
</fileset>
</copy>
</target>
<!--=============================================================
Compile
================================================================= -->
<macrodef name="do_compile">
<attribute name="srcref" />
<attribute name="classpathref" />
<attribute name="output" />
<sequential>
<mkdir dir="@{output}" />
<javac destdir="@{output}" debug="${javac.debug}" memoryMaximumSize="1024m"
fork="yes" nowarn="yes">
<compilerarg line="${javac.args}" />
<classpath refid="@{classpathref}" />
<src refid="@{srcref}" />
</javac>
</sequential>
</macrodef>
<!--=============================================================
Run Tests
================================================================= -->
<property name="junit.fork.dir" value="${basedir}" />
<property name="junit.output.dir" value="${target.dir}/test/junit" />
<property name="junit.haltonfailure" value="false" />
<target name="test" description="run all tests, if needed"
depends="check.tests.run" if="tests.run">
<antcall target="test.clean" />
<antcall target="test.compile" />
<!-- <antcall target="test.instrument" /> -->
<antcall target="test.unit" />
<antcall target="test.report" />
<antcall target="test.coverage" />
</target>
<target name="test.compile" depends="compile" description="compile the test
sources">
<mkdir dir="${test.classes.dir}" />
<antcall target="compile_test" />
</target>
<target name="compile_test" if="test.java.available">
<do_compile srcref="test.src.path" classpathref="test.compile.classpath"
output="${test.classes.dir}" />
</target>
<target name="test.clean" description="Clean test output, forces tests to
be run." unless="tests.uptodate">
<delete dir="${test.output.dir}" />
<delete dir="${main.instrumented.classes.dir}" />
<delete file="cobertura.ser" />
</target>
<target name="test.report" unless="tests.uptodate">
<description>Generate the test reports</description>
<delete dir="${test.report.dir}/reports" />
<junitreport todir="${test.report.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${test.report.dir}/reports" />
</junitreport>
</target>
<target name="check.tests.run" depends="check.tests.uptodate">
<description>Check if utest or atest timestamps are older than the QFJ
classes and test needs to be run</description>
<condition property="tests.run">
<and>
<not>
<isset property="tests.uptodate" />
</not>
<isset property="run.tests" />
</and>
</condition>
</target>
<target name="check.tests.uptodate" depends="check.utests.uptodate">
<description>Check if utest or atest timestamps are older than the QFJ
classes</description>
<condition property="tests.uptodate">
<and>
<isset property="utests.uptodate" />
</and>
</condition>
</target>
<target name="test.init">
<mkdir dir="${test.output.dir}/junit" />
<mkdir dir="${test.output.dir}/reports" />
</target>
<target name="check.utests.uptodate">
<description>Check if any classes are newer than the timestamp
file</description>
<uptodate property="utests.uptodate" targetfile="${utest.timestamp}">
<srcfiles dir="${main.classes.dir}" includes="**/*" />
</uptodate>
</target>
<property name="utest.fork" value="yes" />
<property name="utest.timestamp"
value="${target.dir}/test/.utest_timestamp" />
<target name="test.unit" description="run unit tests"
depends="check.utests.uptodate,test.unit.junit" unless="utests.failed">
<description>Update test timestamp if tests passed.</description>
<touch file="${utest.timestamp}" />
</target>
<target name="test.unit.junit" />
<!--=============================================================
Tests Coverage Report
================================================================= -->
<!--
<path id="cobertura.classpath" description="CoberTura tool path">
<fileset dir="${test.common.lib.dir}">
<include name="cobertura*.jar" />
<include name="log4j*.jar" />
<include name="asm*.jar" />
<include name="jakarta-oro*.jar" />
</fileset>
</path>
<taskdef classpath="cobertura.jar" resource="tasks.properties"
classpathref="cobertura.classpath"/>
<target name="test.instrument">
<cobertura-instrument todir="${main.instrumented.classes.dir}">
<fileset dir="${main.classes.dir}">
<include name="**/*.class"/>
</fileset>
</cobertura-instrument>
</target>
<target name="test.coverage">
<cobertura-report srcdir="${main.src.dir}"
destdir="${test.coverage.report.dir}"/>
</target>
-->
<!-- Step 1: Import JaCoCo Ant tasks -->
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="lib/test/jacocoant.jar" />
</taskdef>
<target name="clean.jacoco">
<delete dir="${result.dir}" />
</target>
<target name="compile.jacoco">
<mkdir dir="${result.classes.dir}" />
<javac srcdir="${src.dir}" destdir="${result.classes.dir}" debug="true"
includeantruntime="false" />
</target>
<target name="test.coverage" depends="compile">
<!-- Step 2: Wrap test execution with the JaCoCo coverage task -->
<jacoco:coverage destfile="${result.exec.file}">
<java classname="org.jacoco.examples.parser.Main" fork="true">
<classpath path="${result.classes.dir}" />
<arg value="2 * 3 + 4" />
<arg value="2 + 3 * 4" />
<arg value="(2 + 3) * 4" />
<arg value="2 * 2 * 2 * 2" />
<arg value="1 + 2 + 3 + 4" />
<arg value="2 * 3 + 2 * 5" />
</java>
</jacoco:coverage>
</target>
<target name="report" depends="test.coverage">
<!-- Step 3: Create coverage report -->
<jacoco:report>
<!-- This task needs the collected execution data and ... -->
<executiondata>
<file file="${result.exec.file}" />
</executiondata>
<!-- the class files and optional source files ... -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${result.classes.dir}" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}" />
</sourcefiles>
</structure>
<!-- to produce reports in different formats. -->
<html destdir="${result.report.dir}" />
<csv destfile="${result.report.dir}/report.csv" />
<xml destfile="${result.report.dir}/report.xml" />
</jacoco:report>
</target>
</project>
</html>
Regards,
ABHAY
Cheers,
ABHAY
On Thu, Aug 7, 2014 at 10:46 PM, Marc R. Hoffmann <
[email protected]> wrote:
> Hi Abhay,
>
> you're probably using the wrong JAR file. org.jacoco.ant_xxx.jar does not
> include the required dependencies. Please use the JAR file called
> "jacocoant.jar" from the JaCoCo download. See documentation:
> http://www.eclemma.org/jacoco/trunk/doc/ant.html
>
> Best regards,
> -marc
>
>
>
> On 07.08.14 17:12, [email protected] wrote:
>
>> Hi All,
>>
>>
>> I am using ant to invoke Jacoco in my project. The <task def > in my
>> common module.xml looks something like Below. This is from the sample on
>> the Jacoco site. I am getting the following error. All the jars are present
>> in the lib/test folder.
>>
>> jar:file:/C:/BRASS/workspace/Java1.7_14.1.x/lib/test/org.
>> jacoco.ant.jar!/org/jacoco/ant/antlib.xml:19: taskdef A class needed by
>> class org.jacoco.ant.ReportTask cannot be found: org/jacoco/core/analysis/
>> ICoverageVisitor
>>
>> using the classloader AntClassLoader[C:\BRASS\
>> workspace\Java1.7_14.1.x\lib\test\org.jacoco.ant.jar;C:\
>> ant-1.8.2\lib\ant-launcher.jar;C:\ant-1.8.2\lib\ant-
>> antlr.jar;C:\ant-1.8.2\lib\ant-apache-bcel.ja
>> r;C:\ant-1.8.2\lib\ant-apache-bsf.jar;C:\ant-1.8.2\lib\ant-
>> apache-log4j.jar;C:\ant-1.8.2\lib\ant-apache-oro.jar;C:\ant-
>> 1.8.2\lib\ant-apache-regexp.jar;C:\ant-1.8.2\lib\ant-
>> apache-resolver.jar;C:\ant-1
>> .8.2\lib\ant-apache-xalan2.jar;C:\ant-1.8.2\lib\ant-
>> commons-logging.jar;C:\ant-1.8.2\lib\ant-commons-net.jar;C:
>> \ant-1.8.2\lib\ant-jai.jar;C:\ant-1.8.2\lib\ant-javamail.
>> jar;C:\ant-1.8.2\lib\ant-jdepend
>> .jar;C:\ant-1.8.2\lib\ant-jmf.jar;C:\ant-1.8.2\lib\ant-jsch.
>> jar;C:\ant-1.8.2\lib\ant-junit.jar;C:\ant-1.8.2\lib\
>> ant-junit4.jar;C:\ant-1.8.2\lib\ant-netrexx.jar;C:\ant-1.
>> 8.2\lib\ant-swing.jar;C:\ant-1.
>> 8.2\lib\ant-testutil.jar;C:\ant-1.8.2\lib\ant.jar;C:\Program
>> Files\Java\jdk1.6.0_38\lib\tools.jar]
>>
>> Total time: 1 second
>>
>>
>>
>> <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/
>> antlib.xml">
>> <classpath path="lib/test/org.jacoco.ant.jar" />
>> </taskdef>
>> <target name="clean.jacoco">
>> <delete dir="${result.dir}" />
>> </target>
>> <target name="compile.jacoco">
>> <mkdir dir="${result.classes.dir}" />
>> <javac srcdir="${src.dir}" destdir="${result.classes.dir}"
>> debug="true" includeantruntime="false" />
>> </target>
>>
>> <target name="test.coverage" depends="compile">
>>
>> <!-- Step 2: Wrap test execution with the JaCoCo coverage
>> task -->
>> <jacoco:coverage destfile="${result.exec.file}">
>> <java classname="org.jacoco.examples.parser.Main"
>> fork="true">
>> <classpath path="${result.classes.dir}" />
>> <arg value="2 * 3 + 4" />
>> <arg value="2 + 3 * 4" />
>> <arg value="(2 + 3) * 4" />
>> <arg value="2 * 2 * 2 * 2" />
>> <arg value="1 + 2 + 3 + 4" />
>> <arg value="2 * 3 + 2 * 5" />
>> </java>
>> </jacoco:coverage>
>> </target>
>> <target name="report" depends="test">
>> <!-- Step 3: Create coverage report -->
>> <jacoco:report>
>> <!-- This task needs the collected execution data
>> and ... -->
>> <executiondata>
>> <file file="${result.exec.file}" />
>> </executiondata>
>> <!-- the class files and optional source files
>> ... -->
>> <structure name="JaCoCo Ant Example">
>> <classfiles>
>> <fileset
>> dir="${result.classes.dir}" />
>> </classfiles>
>> <sourcefiles encoding="UTF-8">
>> <fileset dir="${src.dir}" />
>> </sourcefiles>
>> </structure>
>> <!-- to produce reports in different formats. -->
>> <html destdir="${result.report.dir}" />
>> <csv destfile="${result.report.dir}/report.csv"
>> />
>> <xml destfile="${result.report.dir}/report.xml"
>> />
>> </jacoco:report>
>>
>> Reagrds,
>> ABHAY
>>
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "JaCoCo and EclEmma Users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/jacoco/2k4Q1R3cQWI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.