Jboss EAP 7.4.8配置jacoco 端口无法开启 启动报错

文章描述了在使用JbossEAP7.4.8和JDK17时,配置jacoco(0.7.9版本)进行代码覆盖率测试遇到的启动异常问题。问题在于jacoco版本与JDK版本不兼容,导致类无法被instrument。通过切换到jacoco-0.8.8版本,问题得到解决,8044端口成功开启。解决方案强调了软件版本兼容性的重要性。

项目场景:

servers: Jboss EAP 7.4.8
JDK: JDK17
jacoco: 测试jacoco-0.7.9 jacoco-0.8.5 jacoco-0.8.8

问题描述

问题1:

Jboss 启动 VM arguments追加, 如下启动参数:

-javaagent:F:\CoverageReport\jacoco-0.7.9\lib\jacocoagent.jar=includes=*,output=tcpserver,port=8044,address=0.0.0.0

启动报错

Exception in thread "main" java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:491)
	at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:503)
Caused by: java.lang.RuntimeException: Class java/util/UUID could not be instrumented.
	at org.jacoco.agent.rt.internal_8ff85ea.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140)
	at org.jacoco.agent.rt.internal_8ff85ea.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101)
	at org.jacoco.agent.rt.internal_8ff85ea.PreMain.createRuntime(PreMain.java:55)
	at org.jacoco.agent.rt.internal_8ff85ea.PreMain.premain(PreMain.java:47)
	... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
	at java.base/java.lang.Class.getField(Class.java:2117)
	at org.jacoco.agent.rt.internal_8ff85ea.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
	... 9 more
*** java.lang.instrument ASSERTION FAILED ***: "result" with message agent load/premain call failed at t:\workspace\open\src\java.instrument\share\native\libinstrument\JPLISAgent.c line: 422
FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed

问题2:

修改VM arguments启动参数:
-javaagent:变更为-Djavaagent:

-Djavaagent:F:\CoverageReport\jacoco-0.7.9\lib\jacocoagent.jar=includes=*,output=tcpserver,port=8044,address=0.0.0.0

启动无报错
出现新问题, 8044端口未开启


原因分析:

问题2分析

关于问题2由于端口无法开启, 不使用Eclipse进行启动
EAP-7.4.8\bin\standalone.conf文件中追加如下参数进行
切换为EAP-7.4.8\bin\standalone.bat方式进行启动
端口还是无法开启

JAVA_OPTS="$JAVA_OPTS -javaagent:F:\CoverageReport\jacoco-0.7.9\lib\jacocoagent.jar=includes=*,output=tcpserver,port=8044,address=0.0.0.0"

重新回归Eclipse启动方式
使用-Djavaagent:命令参数
查看EAP-7.4.8\standalone\log\server.log发现
查看log发现下面第一个等号前后存在空格
命令变成成key=value形式
所以导致端口无法开启
javaagent:F:\CoverageReport\jacoco-0.7.9\lib\jacocoagent.jar=includes=*,output=tcpserver,port=8044,address=0.0.0.0

问题1分析

回归到最初问题启动报错
使用-javaagent:命令参数
切换jacoco版本jacoco-0.8.5, 未得到解决
切换jacoco版本jacoco-0.8.8, 启动成功, 8044端口成功开启


解决方案:

切换jacoco版本jacoco-0.8.8, 启动成功, 8044端口成功开启
由于使用JDK17原因导致, 启动报错
重点: 使用最新版本软件, 相对应其他软件需要考虑版本兼容问题
查看EAP-7.4.8\standalone\log\server.log, VM启动参数中存在

VM 参数:  -javaagent:F:\CoverageReport\jacoco-0.8.8\lib\jacocoagent.jar=includes=*,output=tcpserver,port=8044,address=0.0.0.0 

查看cmd命令窗口输入 netstat -aon|findstr "8044"

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值