java - 运行时出现错误 jar 不存在

标签 java docker

运行图像时出现错误:

C:\Users\10649404\Desktop\spring-boot-websocket-chat-demo>docker run -p 5000:8080 ok 2019-04-29 07:10:58.660 INFO org.glowroot - Glowroot version: 0.10.12, built 2018-06-22 00:08:17 +0000 2019-04-29 07:10:58.673 INFO org.glowroot - Java version: 1.8.0_201

这是我没有得到的 jar 文件。它说缺少 lib/glowroot-embedded-collector.jar,即使它存在于该位置。

2019-04-29 07:10:58.682 ERROR org.glowroot - missing lib/glowroot-embedded-collector.jar
2019-04-29 07:10:58.688 ERROR org.glowroot - Glowroot not started: org.glowroot.agent.embedded.init.EmbeddedGlowrootAgentInitFactory
java.lang.ClassNotFoundException: org.glowroot.agent.embedded.init.EmbeddedGlowrootAgentInitFactory
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at org.glowroot.agent.MainEntryPoint.createGlowrootAgentInit(MainEntryPoint.java:311)
        at org.glowroot.agent.MainEntryPoint.start(MainEntryPoint.java:273)
        at org.glowroot.agent.MainEntryPoint.premain(MainEntryPoint.java:173)
        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 org.glowroot.agent.AgentPremain.premain(AgentPremain.java:59)
        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)

这是我的 docker 文件内容:

# Start with a base image containing Java runtime
FROM openjdk:8-jdk-alpine

# Add a volume pointing to /tmp

VOLUME /tmp
# Make port 8080 available to the world outside this container
EXPOSE 8080
ADD /opt/glowroot/glowroot.jar glowroot.jar
ADD /opt/glowroot/lib/glowroot-embedded-collector.jar  glowroot-embedded-collector.jar

ADD /opt/glowroot/lib/glowroot-central-collector-https-linux.jar  glowroot-central-collector-https-linux.jar
ADD /opt/glowroot/lib/glowroot-central-collector-https-osx.jar  glowroot-central-collector-https-osx.jar
ADD /opt/glowroot/lib/glowroot-central-collector-https-windows.jar  
glowroot-central-collector-https-windows.jar
    COPY /opt/glowroot/ /opt/glowroot/ 
    # The application's jar file
    ARG JAR_FILE=target/websocket-demo-0.0.1-SNAPSHOT.jar
    ARG OK=/opt/glowroot/glowroot.jar
    # Add the application's jar to the container
    ADD ${JAR_FILE} websocket-demo.jar
    #ADD ${OK} glowroot.jar
    # Run the jar file 

CMD ["java", "-javaagent:/glowroot.jar","-Dglowroot.agent.id=Docker","-jar", "/websocket-demo.jar"]

请告诉我这个问题。 jar 存在于 lib/glowroot-embedded-collector.jar

最佳答案

在你的 Dockerfile 中你有:

ADD /opt/glowroot/lib/glowroot-embedded-collector.jar  glowroot-embedded-collector.jar

这会复制根目录中的 jar 文件,以便可以在以下位置使用它:/glowroot-embedded-collector.jar

当您说 lib/glowroot-embedded-collector.jar 可用时,您是指在主机上还是在容器内?因为根据您的 Dockerfile,我认为它不会出现在容器内。

也许尝试以这种方式更改 ADD 语句:

ADD /opt/glowroot/lib/glowroot-embedded-collector.jar  lib/glowroot-embedded-collector.jar

关于java - 运行时出现错误 jar 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55898722/

相关文章:

docker - Go 可执行文件是如何在 Docker 中创建的?

java - 如何在 android 中将这些数字对齐到小数点?

java - Docker 停止容器自动重新启动

docker - docker for mac的驱动程序名称是什么?

swift - 服务器端 Swift 的 LLDB 远程调试在 docker 和 macOS 中的 Linux 之间失败

docker - 将 docker 与许多交叉构建工具链结合使用

java - 管理java中参数传递的引用

java - Java 垃圾收集如何与循环引用一起使用?

java - Sentry JVM 选项占位符

java - 如何将 CSV 文件解码为 java 对象