Encountered error while trying JCov java coverage utility

423 views Asked by At

Almost everywhere in INTERNET there are these basic steps:

• Compile java files as usual

 javac <source-files>

• “Instrument” the byte code

 java -jar jcov.jar Instr <application classes> 

• Run the code

 java -classpath ...:jcov_file_saver.jar ... 

• Create a report

 java -jar jcov.jar RepGen <jcov xml file> demo 

I was able to instrument class files and jar files both, but couldn't run jar one.

Faced this error:

$ java -cp .:$JCOV/jcov_file_saver.jar -jar BubbleSort.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tdk/jcov/runtime/Collect
    at BubbleSort.main(BubbleSort.java:49)
Caused by: java.lang.ClassNotFoundException: com.sun.tdk.jcov.runtime.Collect
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

)

Can anyone please help me out or direct me to some web-page where I can understand this?

2

There are 2 answers

0
Vikas Tawniya On BEST ANSWER

Using this resolved the issue faced thanks to sumedh's answer which pushed me to understand about various kind of classpaths. Executing instrumented jar:

java -cp . -Xbootclasspath/a:$JCOV/jcov_file_saver.jar -jar BubbleSort.jar
3
Sumedh On

You also need to provide the jcov.jar file as well because it contains the com/sun/tdk/jcov/runtime/Collect class.

To supply the jcov.jar at run time, run this

java -cp .:$JCOV/jcov_file_saver.jar -Xbootclasspath/a:$JCOV/jcov.jar -jar BubbleSort.jar