1

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 Answer 1

9

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
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the detailed answer : it seems in v0.8.4 that only runtime jar has this attribute ...
@jy95 Please re-read carefully - in all versions up to 0.8.4: jar with artifactId org.jacoco.agent and classifier runtime is absolutely identical to lib/jacocoagent.jar from zip-distribution and so both have Premain-Class attribute, whereas jar without classifier never had and does not have this attribute, because it is not agent, but "API to get a local copy of the agent".
just extracted both jars and only found that attribute in the runtime jar :(
@jy95 once again: repo1.maven.org/maven2/org/jacoco/jacoco/0.8.4/jacoco-0.8.4.zip contains lib/org.jacoco.agent-0.8.4.201905082037.jar which is identical to repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.8.4/… and both do not have Premain-Class because this is not agent, but "API to get a local copy of the agent" Same zip contains agent at lib/jacocoagent.jar which is identical to repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.8.4/… and both have Premain-Class. Hope clear now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.