gpt4 book ai didi

java - 在 Docker 上运行 Java Swing GUI 应用程序

转载 作者:行者123 更新时间:2023-12-02 09:07:36 26 4
gpt4 key购买 nike

我正在尝试使用 Windows 中的 docker 工具箱运行自定义 java swing GUI。我现在想容器化此应用程序,但出现以下错误:

Exception in thread "main" java.lang.UnsatisfiedLinkError: 
/opt/jdk1.8.0_202/jre
/lib/amd64/libawt_xawt.so: libXext.so.6: cannot open shared object file:
No such file or directory

我正在运行一个 dockerfile。设置为:

1) Install Linux

2) Install JDK

3) Copy over the folder containing the JAR

4) run the docker container which would bring up the GUI ( not the linux front-end , not using a vnc is preferred).

我在 Windows 上的终端上使用 Xlaunch,并且能够使用它在 docker 上启动 Firefox。

这是第一个 docker 文件

FROM anapsix/alpine-java
COPY ./myJarFolder /home/myJarFolder
CMD ["java","-jar","/home/myJarFolder/myJarFile.jar"]

这是第二个 docker 文件

FROM alpine:3.2

MAINTAINER Anastas Dancha [...]

# Install cURL

RUN apk --no-cache add ca-certificates

# Java Version

ENV JAVA_VERSION_MAJOR 8

ENV JAVA_VERSION_MINOR 45

ENV JAVA_VERSION_BUILD 14

ENV JAVA_PACKAGE jdk

# Download and unarchive Java

RUN mkdir /opt && / curl -jksSLH "Cookie: oraclelicense=accept-securebackup-cookie" && / http://download.oracle.com/otn-pub/java/jdk/${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-b${JAVA_VERSION_BUILD}/${JAVA_PACKAGE}-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar.gz | tar -xzf - -C /opt && / ln -s /opt/jdk1.${JAVA_VERSION_MAJOR}.0_${JAVA_VERSION_MINOR} /opt/jdk && / rm -rf /opt/jdk/*src.zip && /opt/jdk/lib/missioncontrol && /opt/jdk/lib/visualvm && /opt/jdk/lib/*javafx* && /opt/jdk/jre/lib/plugin.jar && /opt/jdk/jre/lib/ext/jfxrt.jar && /opt/jdk/jre/bin/javaws && /opt/jdk/jre/lib/javaws.jar && /opt/jdk/jre/lib/desktop && /opt/jdk/jre/plugin && /opt/jdk/jre/lib/deploy* && /opt/jdk/jre/lib/*javafx* && /opt/jdk/jre/lib/*jfx* && /opt/jdk/jre/lib/amd64/libdecora_sse.so && /opt/jdk/jre/lib/amd64/libprism_*.so && /opt/jdk/jre/lib/amd64/libfxplugins.so && /opt/jdk/jre/lib/amd64/libglass.so && /opt/jdk/jre/lib/amd64/libgstreamer-lite.so && /opt/jdk/jre/lib/amd64/libjavafx*.so && /opt/jdk/jre/lib/amd64/libjfx*.so

# Set environment

ENV JAVA_HOME /opt/jdk

ENV PATH ${PATH}:${JAVA_HOME}/bin

# COPY myJarFolder from local repository to the image

COPY ./myJarFolder /usr/local/myJarFolder

# Start the image with the jar file as the entrypoint

ENTRYPOINT ["java", "-jar", "usr/local/myJarFolder/myJarFile.jar"]

# EOF

我在第一个 dockerfile 中遇到此错误

$ docker run -ti --rm -e DISPLAY=10.193.146.124:0.0 myDocker:1.0 Exception in thread "main" java.lang.UnsatisfiedLinkError: /opt/jdk1.8.0_202/jre /lib/amd64/libawt_xawt.so: libXext.so.6: cannot open shared object file: No such file or directory at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824) at java.lang.Runtime.load0(Runtime.java:809) at java.lang.System.load(System.java:1086) at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1845) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1122) at java.awt.Toolkit$3.run(Toolkit.java:1636) at java.awt.Toolkit$3.run(Toolkit.java:1634) at java.security.AccessController.doPrivileged(Native Method) at java.awt.Toolkit.loadLibraries(Toolkit.java:1633) at java.awt.Toolkit.(Toolkit.java:1670) at java.awt.Component.(Component.java:593) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa der.java:56)

我在 mkdir/opt 行的第二个 dockerfile 中收到权限错误

有人可以告诉我在 Windows 中执行此操作的正确方法吗?

最佳答案

做了一些更多的研究,通过点击和试用以下代码似乎启动了 GUI,之后出现了一些错误,但这一定是由于 GUI 本身的其他一些问题造成的:

FROM openjdk:8

# Set environment

ENV JAVA_HOME /opt/jdk

ENV PATH ${PATH}:${JAVA_HOME}/bin

# COPY myJarFolder from local repository to the image

COPY ./myJarFolder /usr/local/myJarFolder

# Start the image with the jar file as the entrypoint

ENTRYPOINT ["java", "-jar", "/usr/local/myJarFolder/myJarFile.jar"]

# EOF

关于java - 在 Docker 上运行 Java Swing GUI 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55708634/

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