JavaFX docker is not running

HI All

I have a JavaFX based CLI jar applications used for upgrading the firmware image in to the microchip board. I created a docker image and its not running. But when the jar file application running with standalone app its running.

anees@user-X542UQR:~/BSU/CLI$ docker run -it hello_app1
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:59)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	... 14 more

This is the error for the docker run
Regards
ANees

This tells you that the JAR file is not where the java command is looking for it. Or:

…this may indicate that the JAR in the image is different from the JAR you used without Docker?

To debug, please show us the Dockerfile you used to create the image. And if you specified a custom ENTRYPOINT in the Dockerfile, then also the contents of your script that runs the java command.

Also, please give us the exact docker run command you use.

1 Like

Did you actualy try to run the jar from the commandline on the host or just from the IDE (where everything is configured in the project settings and your run profile)?

If I remember right, starting with java 11, JavaFX is extracted in a seperate JavaFX SDK. Did you include the SDK in your image and need to add it to your classpath.

Even though you happen to have the problem within a docker container, it is rather a java problem and not a docker problem.

Also: a docker container is not able to run desktop applications by default. On a linux system you can mount the x11 demon socket into the container and use it to render the desktop application on the xserver of the host… make sure to add -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY -h $HOSTNAME -v $HOME/.Xauthority:/home/$USER/.Xauthority in front of the image name for that. This will not work with Docker Desktop for Windows - and I have no idea if it does with Desktop Desktop for Mac.

1 Like

Dear Sir

Thanks for your reply.

I hereby attached all the details with you. Please help me to fix this issue as soon as possible. Also please let me know which version of java jdk is used for this?

Dockerfile - Dockerfile
Eclipse_JavaFX_Running_Screenshot.png - JavaFX build and running using Eclipse IDE- We used the JDK as jdk1.8.0_311 in the eclipse
JavaFX_CLI_jdk_1_8_0_311_running.png - We used the jdk1.8.0_311 java binary for running in the CLI the build jar file using eclipse.
JavaFX_CLI_zulu8.40.0.25-ca-fx-jre8.0.222-linux_x64 - We used this jre copied from the Java Unified Host controller application provided by Microchip and ran the build Jar file using eclipse.
JavaFX_Docker_Buil_Run_Error.png - Docker is built successfully and running those images shows an error.

Regards

Anees

(Attachment Docker_JavaFX_Document.docx is missing)

Dear Sir

Thanks for your reply.

I hereby attached all the details with you. Please help me to fix this issue as soon as possible. Also please let me know which version of java jdk is used for this?

Dockerfile.txt - Dockerfile
Eclipse_JavaFX_Running_Screenshot.png - JavaFX build and running using Eclipse IDE- We used the JDK as jdk1.8.0_311 in the eclipse
JavaFX_CLI_jdk_1_8_0_311_running.png - We used the jdk1.8.0_311 java binary for running in the CLI the build jar file using eclipse.
JavaFX_CLI_zulu8.40.0.25-ca-fx-jre8.0.222-linux_x64 - We used this jre copied from the Java Unified Host controller application provided by Microchip and ran the build Jar file using eclipse.
JavaFX_Docker_Buil_Run_Error.png - Docker is built successfully and running those images shows an error.

Regards

Anees

(Attachment Docker_JavaFX_Document.docx is missing)

Dear Sir

Thanks for your reply.

I hereby attached all the details with you. Please help me to fix this issue as soon as possible. Also please let me know which version of java jdk is used for this?

Dockerfile.txt - Dockerfile
Eclipse_JavaFX_Running_Screenshot.png - JavaFX build and running using Eclipse IDE- We used the JDK as jdk1.8.0_311 in the eclipse
JavaFX_CLI_jdk_1_8_0_311_running.png - We used the jdk1.8.0_311 java binary for running in the CLI the build jar file using eclipse.
JavaFX_CLI_zulu8.40.0.25-ca-fx-jre8.0.222-linux_x64 - We used this jre copied from the Java Unified Host controller application provided by Microchip and ran the build Jar file using eclipse.
JavaFX_Docker_Buil_Run_Error.png - Docker is built successfully and running those images shows an error.

Regards

Anees

(Attachment JavaFX.zip is missing)

Dear Sir

Thanks for your reply.

I hereby attached all the details with you. Please help me to fix this issue as soon as possible. Also please let me know which version of java jdk is used for this?

Dockerfile.txt - Dockerfile
Eclipse_JavaFX_Running_Screenshot.png - JavaFX build and running using Eclipse IDE- We used the JDK as jdk1.8.0_311 in the eclipse
JavaFX_CLI_jdk_1_8_0_311_running.png - We used the jdk1.8.0_311 java binary for running in the CLI the build jar file using eclipse.
JavaFX_CLI_zulu8.40.0.25-ca-fx-jre8.0.222-linux_x64 - We used this jre copied from the Java Unified Host controller application provided by Microchip and ran the build Jar file using eclipse.
JavaFX_Docker_Buil_Run_Error.png - Docker is built successfully and running those images shows an error.

Regards

Anees

JavaFX.tar.gz (1.83 MB)

Please try to not answer the discussions with mails that have the same content.

I am quite puzzled why you use different java variations on the host and a diferent (your Dockfile says amazoncorretto:8) variation inside the container.

Since you know that it’s running with one of the variations you have on your host, it makes most sense to use the COPY instruction to copy one of those variations into your image and use it to execute the command.

The problem, that docker will not support Desktop applications out of the box is not addressed by your commands. I gave an example of how the docker run command needs to be extended to make the container render a desktop application on the hosts xserver.

I would avoid to use the /tmp folder to store your data in the image.

Dear Sir

Thanks for your reply

I tried a couple of Java JDK versions and all the versions have the same issues. The one and only java that is working through CLI [not docker] is mentioned in my previous mail. Can you please tell me how I can use the Java folder which I used in my system through CLI in docker ? I used the COPY command and copied the Java folder into the /tmp folder and used that /tmp/java in the CMD command and it’s not working. Can you please help me how can I use the Java which I am working on in my system into docker image? Also which location i used instead of /tmp folder location? I didn’t see any attachment on your side for the sample example. please check and let me know

Regards
Anees

It was at the end of my first response…

Please share the Dockerfile where you tried it. Please forgive me, but I am not going to write an example out of the blue.

I would use /opt or /app or whatever you like, just not /tmp.

Dear Sir

Please find the Dockerfile.txt attached with this. Please review and let me know your comments.

Thanks & Regards
Anees

Dockerfile.txt (285 Bytes)

Looks good to me with one exception:

COPY /home/anees/java/jdk1.8.0_311/ /opt/

Files outside the build directory are not copied into the build comtext and therefor can not be copied into the image like this.

To fix this, the jdk1.8.0_311 folder must be a subfolder of the location where you Dockerfile is.

Hi Sir

I changed the dockerfile based on your comments and here are the output

anees@user-X542UQR:~/BSU/CLI$ docker build -t javafx_cli .
Sending build context to Docker daemon 633.9MB
Step 1/6 : FROM amazoncorretto:8
—> df898fc2e544
Step 2/6 : COPY map.jar /opt
—> 97c187d644c7
Step 3/6 : COPY ip.txt /opt
—> ec74f9365c69
Step 4/6 : COPY BSU_AudioSender_Phy0_Rel_Ver_2_0_15_07_01.hex /opt
—> 3b41292032cd
Step 5/6 : COPY jdk1.8.0_311/ /opt/
—> 98ab15b2a46b
Step 6/6 : CMD [“/opt/jdk1.8.0_311/bin/java”,“-jar”,“/opt/map.jar”,“/opt/ip.txt”,“/opt/BSU_AudioSender_Phy0_Rel_Ver_2_0_15_07_01.hex”]
—> Running in a419e243deb1
Removing intermediate container a419e243deb1
—> d27a3e7e572c
Successfully built d27a3e7e572c
Successfully tagged javafx_cli:latest
anees@user-X542UQR:~/BSU/CLI$ docker run -it javafx_cli
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: “/opt/jdk1.8.0_311/bin/java”: stat /opt/jdk1.8.0_311/bin/java: no such file or directory: unknown.
ERRO[0000] error waiting for container: context canceled

Regards
Anees

Please try docker run -it --entrypoint sh javafx_cli ls /opt/ and see if the jdk1.8.0_311 is inside or wether the whole content of the folder is copied into /opt`

Dear Sir

I can’t run those commands you mentioned in the mail.
anees@user-X542UQR:~/BSU/CLI$ docker run -it --entrypoint sh javafx_cli ls /opt/
sh: 0: Can’t open ls

I finally fixed those errors and still have two more errors. Please help me resolve those errors.

anees@user-X542UQR:~/BSU/CLI$ sudo docker run -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY -it javafx_cli
[sudo] password for anees:
Number of ips = 1
10.42.0.236
libGL error: MESA-LOADER: failed to retrieve device information
Prism-ES2 Error : GL_VERSION (major.minor) = 1.3

(java:1): dbind-WARNING **: 18:28:48.954: Couldn’t connect to accessibility bus: Failed to connect to socket /tmp/dbus-8EdID7oYGS: Connection refused
Gtk-Message: 18:28:48.986: Failed to load module “canberra-gtk-module”
Gtk-Message: 18:28:48.988: Failed to load module “canberra-gtk-module”
Jul 19, 2022 6:28:49 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
Trying to Connect: 10.42.0.236
Enter 1 times
Hex File (re)loaded…
Reading Version …

Please find the attached the updated dockerfile

Regards
Anees

(Attachment Dockerfile is missing)

Dear Sir

I can’t run those commands you mentioned in the mail.
anees@user-X542UQR:~/BSU/CLI$ docker run -it --entrypoint sh javafx_cli ls /opt/
sh: 0: Can’t open ls

I finally fixed those errors and still have two more errors. Please help me resolve those errors.

anees@user-X542UQR:~/BSU/CLI$ sudo docker run -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY -it javafx_cli
[sudo] password for anees:
Number of ips = 1
10.42.0.236
libGL error: MESA-LOADER: failed to retrieve device information
Prism-ES2 Error : GL_VERSION (major.minor) = 1.3

(java:1): dbind-WARNING **: 18:28:48.954: Couldn’t connect to accessibility bus: Failed to connect to socket /tmp/dbus-8EdID7oYGS: Connection refused
Gtk-Message: 18:28:48.986: Failed to load module “canberra-gtk-module”
Gtk-Message: 18:28:48.988: Failed to load module “canberra-gtk-module”
Jul 19, 2022 6:28:49 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
Trying to Connect: 10.42.0.236
Enter 1 times
Hex File (re)loaded…
Reading Version …

Please find the attached the updated dockerfile

Regards

Anees

Dockerfile.txt (1.35 KB)

I am surprised that it doesn’t work. Though, the error message “/opt/jdk1.8.0_311/bin/java: no such file or directory: unknown.” made me think there is a problem with the path, the command should only provide evidence about if a path problem exists. Though, since you doesn’t seem to have the path problem anymore, the command became irrelevant.

When it commes to running your javafx application inside a container. I shared what I know about running desktop applications in containers. As I don’t believe and don’t use desktop applications in containers, I can’t realy help you with the error messages you get now. It looks like javafx expects some library to be existing that don’t exist and some requirements opengl. You’ll have to wait till someone commes around that is able to make sense of it or investigate yourself.

Good luck!

Dear Sir

We have run the docker file and we got the following error. Can you please check this error

anees@user-X542UQR:~/BSU/CLI$ sudo docker run -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY -it javafx_cli

libGL error: MESA-LOADER: failed to retrieve device information
Prism-ES2 Error : GL_VERSION (major.minor) = 1.3

(java:1): dbind-WARNING **: 06:05:36.529: Couldn’t connect to accessibility bus: Failed to connect to socket /tmp/dbus-8EdID7oYGS: Connection refused

Regards
Anees