0

I have a GUI applicationwith javafx on a jar file which runs perfectly on my pc on ubuntu 18.10 with openjdk8 and openjfx installed.

But when I do the same on Docker with my Dockerfile like this:

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

Then building (successfully) and running it with those commands:

docker build -t app1 .
docker run app1

It shows me the following error:

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

I tried every forum on the subject but I still cannot understand where this error comes from. Can someone help me with this ?

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

I built and ran it with same commands and now I'm getting this error:

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

My application should display a window when it runs. I read somewhere that docker cannot do this. Is it true ?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Nabil Sabour
  • 1
  • 1
  • 2
  • When you say it runs on your PC, are you running it with `java -jar myapp.jar`? – DazWilkin Jul 02 '19 at 19:29
  • The command should be `docker run --interactive --tty app1` (`app1` is the name of the image to run, not the name of your app) – DazWilkin Jul 02 '19 at 19:30
  • Possible duplicate of [What does “Could not find or load main class” mean?](https://stackoverflow.com/q/18093928/5221149) – Andreas Jul 02 '19 at 19:34
  • Sorry for the mistake, I edited my post. I do the command "docker run app1" for docker. I tried with "docker run --interactive --tty app1" but still the same error. On my pc i do java -jar myapp.jar and it's working fine. – Nabil Sabour Jul 02 '19 at 19:35
  • I took Macagua's HelloWorld sample, compiled it, jar'd it and ran it locally. Then I used your Dockerfile (replacing `myapp.jar` with `Main.jar` and it runs without issue. Perhaps try this trivial example and see what happens? https://github.com/macagua/example.java.helloworld – DazWilkin Jul 02 '19 at 21:38
  • I've already tested this example before and it worked fine with docker. I just changed my Dockerfile, which looks like this now: – Nabil Sabour Jul 03 '19 at 18:28
  • I've already tested this example before and it worked fine with docker. But I don't have the same error anymore, I edited my post. Thanks for helping me. – Nabil Sabour Jul 03 '19 at 18:36

1 Answers1

0

I added few lines to my Dockerfile to install some graphical librairies and i ran the image like this:

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

Added on behalf of question asker.

Dharman
  • 30,962
  • 25
  • 85
  • 135