设置log4j.configurationFactory系统属性后,JaCoCo停止工作

时间:2017-05-10 13:14:25

标签: java log4j jacoco

JaCoCo在设置log4j.configurationFactory系统属性后停止工作。

java.lang.reflect.InvocationTargetException
FATAL ERROR in native method: processing of -javaagent failed
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
    at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.lang.RuntimeException: Class java/util/UUID could not be instrumented.
    at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140)
    at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101)
    at org.jacoco.agent.rt.internal_6da5971.PreMain.createRuntime(PreMain.java:55)
    at org.jacoco.agent.rt.internal_6da5971.PreMain.premain(PreMain.java:47)
    ... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
    at java.lang.Class.getField(Class.java:1703)
    at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
    ... 9 more
Exception in thread "main" 

我已经阅读过类似于JaCoCo和JDK 1.8的错误,但它已经在JaCoCo 0.7.7中得到了解决。

VM参数的定义如下:

-Dlog4j.configurationFactory=mytest.CustomConfigurationFactory
-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
-Dcom.sun.management.jmxremote.rmi.port=9090
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=9090
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=localhost
-javaagent:/path/jacocoagent.jar=destfile=C:/TEMP/jacoco.exec,jmx=true

我正在使用:

  • JaCoCo 0.7.7
  • Log4j 2.8.1
  • JDK 1.8.0_102

有谁知道如何解决它?

1 个答案:

答案 0 :(得分:4)

正如JaCoCo users mailing list中所回答:

JaCoCo(截至目前为0.7.9的最新版本),使用Log4j JDK日志适配器时JMX和Logging以及JaCoCo代理注册JMX MBean之间的交互似乎存在实际问题。在此期间,更深入的调查需要一些时间

  • JaCoCo代理应该配置为不注册JMX MBean,即没有jxm=true或等同于jxm=false-javaagent:jacocoagent.jar=jmx=false),应该注意JMX不是只有远程连接到JaCoCo代理的选项 - output=tcpserver output=tcpclient‑Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager

  • 不应使用Log4j JDK记录适配器,即不使用# This solution only prints unique elements in df1 which are not in df2 np.setdiff1d(df1,df2) Out[236]: array(['b0002'], dtype=object)

更新

这是一张修复JaCoCo方面的门票,解释了会发生什么 - have a look