问题
I am passing jacocoagent.jar
of version 0.8.1 as a java agent to record the code coverage on the server to my server start-up script. But I see that Pre-main class attribute is missing in the jar, as a result, I get the following error:
Error occurred during initialization of VM
Failed to find Premain-Class manifest attribute in
/u01/jetty_home/jacoco/jacocoagent.jar
agent library failed to init: instrument.
Does anyone have thoughts on how to fix this?
回答1:
Make sure that you use proper JAR file.
lib/jacocoagent.jar
in jacoco-0.8.1.zip
that is linked from JaCoCo homepage has following checksums
$ wget http://repo1.maven.org/maven2/org/jacoco/jacoco/0.8.1/jacoco-0.8.1.zip
$ unzip jacoco-0.8.1.zip
$ md5sum lib/jacocoagent.jar
2873d7006dc9672d84981792df2c5b7a lib/jacocoagent.jar
$ sha256sum lib/jacocoagent.jar
cd40d1c1aea4112adb82049df3f462b60380ce1bb00bdecb1cfdb862e34be8dd lib/jacocoagent.jar
JaCoCo homepage also contains link on JaCoCo documentation, which contains page "Maven Repository" with explanation that exactly the same artifact in Maven Central Repository has groupId org.jacoco
, artifactId org.jacoco.agent
and most importantly classifier runtime
:
Following JAR files are available:
Group ID | Artifact ID | Classifier | Description -----------+------------------+------------+------------- ... org.jacoco | org.jacoco.agent | | API to get a local copy of the agent org.jacoco | org.jacoco.agent | runtime | Agent ...
so its filename is org.jacoco.agent-0.8.1-runtime.jar
$ wget http://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.8.1/org.jacoco.agent-0.8.1-runtime.jar
$ md5sum org.jacoco.agent-0.8.1-runtime.jar
2873d7006dc9672d84981792df2c5b7a org.jacoco.agent-0.8.1-runtime.jar
$ sha256sum org.jacoco.agent-0.8.1-runtime.jar
cd40d1c1aea4112adb82049df3f462b60380ce1bb00bdecb1cfdb862e34be8dd org.jacoco.agent-0.8.1-runtime.jar
and both have Premain-Class
attribute
$ unzip lib/jacocoagent.jar
$ cat META-INF/MANIFEST.MF | grep Premain
Premain-Class: org.jacoco.agent.rt.internal_c13123e.PreMain
来源:https://stackoverflow.com/questions/53644625/code-coverage-for-integration-tests-using-jacoco