3

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?

Vikas Tawniya
  • 1,323
  • 1
  • 13
  • 22

2 Answers2

0

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

Sumedh
  • 638
  • 2
  • 15
  • 26
  • It did helped me to execute jar successfully but it didn't fulfill it's true purpose. It was supposed to generate a file which can be achieved with jcov_file_saver.jar only. And also I checked in this jar that it has the specified class in it, so, I specified it in bootclasspath and it worked. could you please explain me why it worked now and not before ? – Vikas Tawniya Dec 26 '16 at 16:11
  • The reason it worked now was because it needed the Collect class which is in jcov.jar which you provided with Xbootclasspath. Can you mark this question as answered since your initial error has been resolved. Open a new question for other queries. – Sumedh Dec 28 '16 at 07:24
  • Sorry but it didn't get resolved by this but instead I had to pass "jcov_file_saver.jar" in bootclasspath to get it work right. – Vikas Tawniya Dec 28 '16 at 13:08
0

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
Vikas Tawniya
  • 1,323
  • 1
  • 13
  • 22