Dear Echo, JaCoCo comes with its own build. If you want to to build a modified version of JaCoCo I recommend running this build:
http://www.jacoco.org/jacoco/trunk/doc/build.html The artifacts produced by our build are tested and do support offline instrumentation. Regards, -marc On 2017-11-14 09:33, Echo Zhang wrote: > DEAR MARC > Thanks for this quick response. > Because i need to read the source code , i download the code from the > GitHub(https://github.com/jacoco/jacoco). Then i compile the code to generate > the jar > jacocoant.JAR. I am sure i didn't add some statements that can influence the > original source code. In fact ,the on-the fly instrumentation is OK and I can > run it successfully. But when i use offline instrumentation ,it will have the > above errors. > And about the JACOCOAGENT.JAR, i use both the official version and the Github > source code version. I use AGENT .RT FOLDER(shown in the following picture) > to generate the JACOCOAGENT.JAR. I thougnt maybe it's the problem about the > version, so i also tried several official version ,but it didn't work. > > And about JACOCOANT.JAR,i use the AGENT ANT CORE REPORT ASM folders to > genearate JACOCOANT.JAR(it is the same as the official version ). I will show > them in the following. > > [3] > > The reason why i dont use the official version is that i need add some > statements into the source code to finish an experiment. > > Regards, > -Echo > > 在 2017年11月14日星期二 UTC+8下午2:05:34,Echo Zhang写道: > >> 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 [1] >> >> 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> >> [2] >> >> 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/7d1d8463-e44d-48a4-92ba-71d006a87bd9%40googlegroups.com > [4]. > For more options, visit https://groups.google.com/d/optout. Links: ------ [1] http://www.eclipse.org/legal/epl-v10.html [2] https://lh3.googleusercontent.com/-IFbld8-WmvQ/WgqG8SGLhuI/AAAAAAAAABY/ONo1mx41yy0fObQWJyFSUCCkiBYZ21k3gCLcBGAs/s1600/0M81EX%2529A%2528%257EHI%255DE%257B5%255BTO%255B4LE.png [3] https://lh3.googleusercontent.com/-fzykoARmSN4/Wgqok5XJ_CI/AAAAAAAAAB4/HlqlTWAdxsEj0LGWHmTW4cDMtOPp_fWrgCLcBGAs/s1600/%2529QV2%257E%2540WM1%2524XDX8NQ%257DI6%257B_3W.png [4] https://groups.google.com/d/msgid/jacoco/7d1d8463-e44d-48a4-92ba-71d006a87bd9%40googlegroups.com?utm_medium=email&utm_source=footer -- 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/a54bde9b3f6b3786370805a3f2eef6b9%40mountainminds.com. For more options, visit https://groups.google.com/d/optout.
