Hi,All.
I am using ant to invoke Jacoco in my project. when i use the on-the-fly, 
it's OK. But when i use the Offline Instrumentation, i will getting the 
following error. All the jar are present in the lib/ folder. I have been 
confused several days.
Buildfile: E:\Jacoco\build.xml
clean:
   [delete] Deleting directory E:\Jacoco\target
compile:
    [mkdir] Created dir: E:\Jacoco\target\classes
    [javac] Compiling 2 source files to E:\Jacoco\target\classes
instrument:
[jacoco:instrument] Instrumented 2 classes to E:\Jacoco\target\classes-instr
test:
     [java] Exception in thread "main" java.lang.NoClassDefFoundError: 
$jacoco/runtime/package/name$/Offline
     [java] at HelloTest.$jacocoInit(HelloTest.java)
     [java] at HelloTest.main(HelloTest.java)
     [java] Caused by: java.lang.ClassNotFoundException: $jacoco.runtime.
package.name$.Offline
     [java] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
     [java] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
     [java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
     [java] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
     [java] ... 2 more
     [java] Java Result: 1
report:
[jacoco:report] Loading execution data file E:\Jacoco\target\jacoco.exec


BUILD FAILED
E:\Jacoco\build.xml:73: Unable to read execution data file E:\Jacoco\target\
jacoco.exec


Total time: 781 milliseconds
My build.xml is following.
<?xml version="1.0" encoding="UTF-8"?>


<!-- 
   Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors
   All rights reserved. This program and the accompanying materials
   are made available under the terms of the Eclipse Public License v1.0
   which accompanies this distribution, and is available at
   http://www.eclipse.org/legal/epl-v10.html
  
   Contributors:
      Marc R. Hoffmann - initial API and implementation
-->
<!-- offline-->
<project name="Example Ant Build with JaCoCo Offline Instrumentation" 
default="rebuild" xmlns:jacoco="antlib:org.jacoco.ant">
 
 <description>
   Example Ant build file that demonstrates how JaCoCo can be used with
   offline instrumentation. This requires preprocessing of the class files
   before the test is launched and adding the JaCoCo agent to the classpath.
 </description>


 <property name="src.dir" location="./src" />
 <property name="result.dir" location="./target" />
 <property name="result.classes.dir" location="${result.dir}/classes" />
 <property name="result.classes.instr.dir" location="${result.dir}/classes-
instr" />
 <property name="result.report.dir" location="${result.dir}/site/jacoco" />
 <property name="result.exec.file" location="${result.dir}/jacoco.exec" />


 <!-- Step 1: Import JaCoCo Ant tasks -->
 <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
 <classpath path="./lib/jacocoant.jar" />
 </taskdef>


 <target name="clean">
 <delete dir="${result.dir}" />
 </target>


 <target name="compile">
 <mkdir dir="${result.classes.dir}" />
 <javac srcdir="${src.dir}" destdir="${result.classes.dir}" debug="true" 
includeantruntime="false" />
 </target>


 <target name="instrument" depends="compile">
 <!-- Step 2: Instrument class files -->
 <!-- jacoco:instrument见antlib.xml定义-->
 <jacoco:instrument destdir="${result.classes.instr.dir}">
 <fileset dir="${result.classes.dir}" />
 </jacoco:instrument>
 </target>


 
 <target name="test" depends="instrument">
 <!-- Step 3: Run tests with instrumented classes -->
 <java classname="HelloTest" fork="true">
 <!-- jacocoagent.jar must be on the classpath --> 
 <classpath>
 <pathelement path="./lib/jacocoagent.jar"/>
 <pathelement path="${result.classes.instr.dir}" />
 </classpath>
 <!-- Agent is configured with system properties -->
 <sysproperty key="jacoco-agent.destfile" file="${result.exec.file}"/>
 <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>
 </target>


 <target name="report" depends="test">
 <!-- Step 4: 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>


 <target name="rebuild" depends="clean,compile,instrument,test,report" />


</project>
<https://lh3.googleusercontent.com/-IFbld8-WmvQ/WgqG8SGLhuI/AAAAAAAAABY/ONo1mx41yy0fObQWJyFSUCCkiBYZ21k3gCLcBGAs/s1600/0M81EX%2529A%2528%257EHI%255DE%257B5%255BTO%255B4LE.png>




Regrads 

echo

-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/3ce4145e-0506-4996-ad45-2ba83e1a2e09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to