gpt4 book ai didi

java - Docker 容器无法使用 Java 12 运行 jacoco 代理

转载 作者:行者123 更新时间:2023-12-02 09:54:53 25 4
gpt4 key购买 nike

我正在尝试使用我的 Spring Boot 应用程序运行 java docker 镜像。我想用它进行 API 测试,并且还想收集代码覆盖率。但是我无法使 jacocoagent 在 docker 容器内运行。难道我做错了什么?我是否缺少某些地方的设置?当我不添加代理时,常规 bootJar 运行顺利。此外,我可以在 docker env 之外毫无问题地执行相同的命令。所以这似乎不是一个java bug。

这是我的 docker-compose 文件:

version: '3.7'
services:
bootJarTestApi:
image: openjdk:12.0.1-jdk-oracle
environment:
- "JAVA_TOOL_OPTIONS=-javaagent:/jacoco-agent/jacocoagent.jar=destfile=/jacoco-report/apiDockerTest.exec,output=file"
ports:
- 2020:2020
- 2021:2021
volumes:
- "./build/libs/bootJar.jar:/bootJar.jar"
- "./build/libs/jacoco-agent/jacocoagent.jar:/jacoco-agent/jacocoagent.jar"
- "./build/jacoco/:/jacoco-report/"
entrypoint: ["java", "-jar",
# "-javaagent:/jacoco-agent/jacocoagent.jar=destfile=/jacoco-report/apiDockerTest.exec,output=file",
"-Dspring.profiles.active=dev",
"/bootJar.jar"]

当我尝试运行它时,docker 说:

bootJarTestApi_1  | Picked up JAVA_TOOL_OPTIONS: -javaagent:/jacoco-agent/jacocoagent.jar=destfile=/jacoco-report/apiDockerTest.exec,output=file
bootJarTestApi_1 | FATAL ERROR in native method: processing of -javaagent failed
bootJarTestApi_1 | mmap failed for CEN and END part of zip file
bootJarTestApi_1 | Unexpected error (103) returned by AddToSystemClassLoaderSearch
bootJarTestApi_1 | Unable to add /jacoco-agent/jacocoagent.jar to system class path - the system class loader does not define the appendToClassPathForInstrumentation method or the method failed
bootJarTestApi_1 | #
bootJarTestApi_1 | # A fatal error has been detected by the Java Runtime Environment:
bootJarTestApi_1 | #
bootJarTestApi_1 | # SIGSEGV (0xb) at pc=0x00007f85d2728b07, pid=1, tid=7
bootJarTestApi_1 | #
bootJarTestApi_1 | # JRE version: OpenJDK Runtime Environment (12.0.1+12) (build 12.0.1+12)
bootJarTestApi_1 | # Java VM: OpenJDK 64-Bit Server VM (12.0.1+12, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
bootJarTestApi_1 | # Problematic frame:
bootJarTestApi_1 | # C [libc.so.6+0x37b07] abort+0x297
bootJarTestApi_1 | #
bootJarTestApi_1 | # Core dump will be written. Default location: Core dumps may be processed with "/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h %e" (or dumping to //core.1)
bootJarTestApi_1 | #
bootJarTestApi_1 | # An error report file with more information is saved as:
bootJarTestApi_1 | # //hs_err_pid1.log
bootJarTestApi_1 | #
bootJarTestApi_1 | # If you would like to submit a bug report, please visit:
bootJarTestApi_1 | # http://bugreport.java.com/bugreport/crash.jsp
bootJarTestApi_1 | #
bootJarTestApi_1 |
bootJarTestApi_1 | [error occurred during error reporting (), id 0xb, SIGSEGV (0xb) at pc=0x00007f85d2728b07]

最佳答案

看起来错误消息中的关键行是

mmap failed for CEN and END part of zip file

在 Google 中搜索这一行表明它始终与文件系统访问相关,但可能由多种原因引起 - 从错误的操作系统配置到某些文件系统的奇怪行为和 JVM 中的错误。因此,我认为这与特定代理无关,即与 JaCoCo 代理无关,并且您应该能够使用任何其他代理重现相同的情况。

你可以试试

  • 不将卷用于代理文件,而是用于目录;
  • 完全不使用代理的体积并将其直接放入图像中。

关于java - Docker 容器无法使用 Java 12 运行 jacoco 代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56066775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com