gpt4 book ai didi

java - 错误: Could not find or load main class on Docker

转载 作者:行者123 更新时间:2023-12-02 03:36:24 43 4
gpt4 key购买 nike

我有一个在 jar 文件上带有 javafx 的 GUI 应用程序,它可以在安装了 openjdk8 和 openjfx 的 ubuntu 18.10 电脑上完美运行。

但是当我在 Docker 上使用我的 Dockerfile 执行相同操作时,如下所示:

FROM openjdk:8-jdk
RUN apt-get update && apt-get install -y --no-install-recommends openjfx && rm -rf /var/lib/apt/lists/*
ADD myapp.jar myapp.jar
CMD java -jar myapp.jar

然后使用这些命令构建(成功)并运行它:

docker build -t app1 .
docker run app1

它向我显示以下错误:

Error: Could not find or load main class application.Sample

我尝试了有关该主题的每个论坛,但我仍然无法理解此错误来自何处。有人可以帮我解决这个问题吗?

EDIT: I just changed my Dockerfile, which looks like this now:

FROM ubuntu
RUN apt-get update && apt-get install -y openjdk-11-jdk
RUN apt-get update && apt-get install -y --no-install-recommends openjfx && rm -rf /var/lib/apt/lists/*
ADD myapp.jar myapp.jar
CMD java -jar myapp.jar

我使用相同的命令构建并运行它,现在我收到此错误:

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:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61)
Caused by: java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: com.sun.glass.ui.gtk.GtkApplication._isDisplayValid()Z
at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:268)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:269)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.UnsatisfiedLinkError: com.sun.glass.ui.gtk.GtkApplication._isDisplayValid()Z
at com.sun.glass.ui.gtk.GtkApplication._isDisplayValid(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.isDisplayValid(GtkApplication.java:83)
at com.sun.glass.ui.gtk.GtkApplication.<init>(GtkApplication.java:67)
at com.sun.glass.ui.gtk.GtkPlatformFactory.createApplication(GtkPlatformFactory.java:41)
at com.sun.glass.ui.Application.run(Application.java:144)
at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:258)
... 6 more

我的应用程序在运行时应显示一个窗口。我在某处读到 docker 无法做到这一点。这是真的吗?

最佳答案

我在 Dockerfile 中添加了几行来安装一些图形库,然后像这样运行图像:

docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY app1

代表提问者添加。

关于java - 错误: Could not find or load main class on Docker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56858657/

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