I am trying to use JaCoCo for code coverage. I am running Liberty from Eclipse (using the Eclipse launcher). In jvm.options, I added these lines: (substitute <location> for a path)
-Xshareclasses:none
-javaagent:<location>/jacocoagent.jar=destfile=jacoco.exec,output=file,append=false,classdumpdir=./classdump
however, after running the tests, I do not see any coverage information. It looks like JaCoCo cannot link to the Java classes that are in my web application war file.
Is there a different process run by liberty that has the java classes? Can a java agent be attached to that process?
Are you using JaCoCo 0.7.3 or later? If yes, I suspect the problem is caused by changes in issue #272 because last I checked, WebSphere Liberty profile did not define classes with a CodeSource location, so this heuristic in JaCoCo causes all classes in applications running on WebSphere Liberty profile to be ignored. If you can confirm that's the case for your application on some recent Liberty fixpak (
MyClass.class.getProtectionDomain().getCodeSource().getLocation()
), then I would suggest opening a WebSphere RFE, a JaCoCo issue, or both.