0

I'm currently building javafx on my local desktop, and I save all rendered charts as snapshot and save them. Now I'm need to run my javafx program on remote cloud desktop that does not have UI and display. So now I'm encountering this error: Caused by: java.lang.UnsupportedOperationException: Unable to open DISPLAY.

Is there a way around this, can I still get the snapshot without having a display on my remote cloud desktop?

I tried adding -Dglass.platform=Monocle -Dmonocle.platform=Headless -Dprism.order=sw when running on my remote desktop, but the error message is the same. Do I need to install or add any dependency for Monocle to work?

Error message:

     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     [java]     at java.lang.reflect.Method.invoke(Method.java:498)
     [java]     at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:873)
     [java] Caused by: java.lang.UnsupportedOperationException: Unable to open DISPLAY
     [java]     at com.sun.glass.ui.gtk.GtkApplication.lambda$new$5(GtkApplication.java:142)
     [java]     at java.security.AccessController.doPrivileged(Native Method)
     [java]     at com.sun.glass.ui.gtk.GtkApplication.<init>(GtkApplication.java:140)
     [java]     at com.sun.glass.ui.gtk.GtkPlatformFactory.createApplication(GtkPlatformFactory.java:41)
     [java]     at com.sun.glass.ui.Application.run(Application.java:146)
     [java]     at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:257)
     [java]     at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:211)
     [java]     at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:675)
     [java]     at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:337)
     [java]     at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)```


tinaaa
  • 1
  • 1
  • I suppose you can redesign your app so that the GUI calls separate classes for generating charts. The chart generators would know nothing about displaying to the user. Data for the charts gets passed into the chart generator, and out comes chart image. Once you separate chart generation from the GUI, you can write a console app or a Servlet that calls the chart generator in the same way that your GUI calls the chart generator. The chart generator does not know, and does not care, if it is being called from a GUI, from a console app, or from a Servlet. – Basil Bourque Jun 23 '22 at 20:59
  • Yes that would work, the things is, I couldn't find a good chart generator for Java. Do you know any good chart generator for java? – tinaaa Jun 23 '22 at 21:38
  • Library recommendations are out of scope. But you are already using JavaFX and JavaFX can generate charts and snapshot them to image files via ImageIO. You can then return the images as proposed by Basil. So JavaFX could act as your chart generator, though there is another technology you can use for that if you wish. – jewelsea Jun 23 '22 at 22:02
  • Yes, I'm using javafx to take snapshot and save the images, but now I cannot run the program because cloud desktop do not have display, what is a way to still use javafx to create chart, but do not start the UI so it would not error "Unable to open DISPLAY"? – tinaaa Jun 23 '22 at 22:07
  • If you choose to create a JavaFX as your a chart generator, you could package it using jpackage. jpackage will create an RPM or DEB file for installation on the server. The generated package will contain your app and the required java runtime, it will also include dependencies for OS packages for setting up the display and graphics pipelines required via JavaFX. So when you install your app package it will also install the required OS and library software needed for the display. That is just one idea, you don't need to follow that. – jewelsea Jun 23 '22 at 22:08
  • There are some StackOverflow questions on [JavaFX and the message: Unable to open DISPLAY](https://stackoverflow.com/search?q=%5Bjavafx%5D+Unable+to+open+DISPLAY) you could look at. From my recollection (it has been a while), the display is an environment setting and configuration for the X-Windows environment on Linux, [some background (and unrelated) info on display](https://datacadamia.com/ssh/x11/display). Every graphical application needs to know its x window display to display on, though I don't think it needs to be a physical display and can be virtual for a server. – jewelsea Jun 23 '22 at 22:12
  • 1
    JavaFX can also run in a [headless mode](https://stackoverflow.com/questions/20279336/javafx-in-headless-mode) (I don't know if that answer is still applicable but maybe). It can also use a rendering platform designed for embedded systems without windowing toolkits or using headless modes called [Monocole](https://wiki.openjdk.org/display/OpenJFX/Monocle), I have not used it. Monocle may help, but it is probably easier to run your app on a server with a windowing system and full graphics pipeline with the display environment variable configured with Xvfb running. – jewelsea Jun 23 '22 at 22:18
  • Try nailgun's solution: [JavaFX for server-side image generation](https://stackoverflow.com/questions/17940329/javafx-for-server-side-image-generation) (perhaps this question can be closed as a duplicate of that). – jewelsea Jun 23 '22 at 22:18
  • "Do I need to install or add any dependency for Monocle to work?" -> I think you do, at least for recent JavaFX releases. I don't use Monocle so haven't tried it. And JavaFX is available in different forms like the SDK, downloadable JMODs or Maven dependencies. But, at least for Maven (which is my primary usage), monocle jars are different than others. You can see the [jars in maven for 17.0.2 here](https://repo1.maven.org/maven2/org/openjfx/javafx-graphics/17.0.2/), the monocle ones are different. – jewelsea Jun 23 '22 at 22:48
  • I think to use the Monocle jars, you need to apply a Monocle-specific classifier, e.g. `linux-monocle`, similar to this [cross-platform fat jar answer](https://stackoverflow.com/questions/52653836/maven-shade-javafx-runtime-components-are-missing). You don't actually (and I wouldn't) need to build a fat jar, but you do need to have classified dependencies for your target platforms for your app to work on them (and Monocle is technically a different classified target platform the way it is currently setup). – jewelsea Jun 23 '22 at 22:53
  • Also the maven jars for different running Monocle on different platforms aren't in Maven for all JavaFX versions and platform modules, 17.0.2 jars linked previously have more classified Monocle jars to support more platforms than [18.0.1 jars](https://repo1.maven.org/maven2/org/openjfx/javafx-graphics/18.0.1/). Gluon also offers a [Monocle SDK](https://gluonhq.com/products/javafx/). I don't know if that is freely downloadable or requires a support contract. – jewelsea Jun 23 '22 at 22:56
  • In retrospect, the question about Monocle is complicated enough that it could have been a separate question from the DISPLAY question. Although the end result required is the same (rendering a JavaFX app on the server), the two approaches are likely orthogonal in their implementation. – jewelsea Jun 23 '22 at 22:57

0 Answers0