简体   繁体   中英

How to externalize the properties of a jacoco javaagent

I'm trying to get code coverage data from a remote server, so I added a JVM argument:

-javaagent:/opt/jacocoagent.jar=output=tcpserver,port=6300,includes="a pretty long list"

but unfortunately the includes list is too long, that the java command has exceeded the maximum length of our system limits.

Is there any way to specify a external property file so I can put the long "includes list” there?

I've read the jacoco document, it seems when running in "Offline Instrumentation", the jacoco agent will read properties from jacoco-agent.properties if it appears in classpath. But I don't want to use this mode.

Found a solution myself. When oracle JVM startup, it picks an environment variable JAVA_TOOL_OPTIONS and

the JNI_CreateJavaVM function (in the JNI Invocation API) prepends the value of the environment variable to the options supplied in its JavaVMInitArgs argument.

So in my case, I defined: JAVA_TOOL_OPTIONS=-javaagent:/path/to/jacocoagent.jar=output=tcpserver,address=*,port=6300,includes=" a pretty long list "

For details, you can refer to: https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/envvars002.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM