Deploy JavaFX on Ubuntu server without display
Asked Answered
C

3

5

I'm developing a JavaFX application using jdk1.7.0_51 on Mac OS X (10.9.1) in Netbeans. I can run it without a problem and after a clean build I can also launch the jar from the dist/ folder.

Now I want to deploy this on a 64 bit Ubuntu 13.04 server. I've had a lot of issues doing this but have finally set up the server to have the correct JRE, fonts and libraries. Running the jar resulted in errors going way deeper than my code (going to UnsatisfiedLinks to native libraries where MACOS was mentioned) so I figured it would be best to package my app on Ubuntu itself. I ended up installing NetBeans to make a new (native) JavaFX project and uploaded the src/ and lib/ folders from my machine using sftp. Running the code through the reconstructed project in NetBeans works fine, though I get a warning in the console during run:

libGL error: failed to load driver: swrast
libGL error: Try again with LIBGL_DEBUG=verbose for more details.
Prism-ES2 Error : GL_VERSION (major.minor) = 1.4

Regardless, the application DOES run. After a clean build, I can similarly run the jar from the dist/ folder. The same warning appears in the terminal but then the application launches.

However, if I ssh to the server without the -X flag and try to run the application, I get the following:

Failed in XOpenDisplay
(java:29341): Gtk-WARNING **: cannot open display: 

However, my application does not have a UI. It simply uses JavaFX for the WebEngine (this is required and can not be changed). I was wondering if anyone knows if (and if so, how) it's possible to launch my JavaFX jar without a display (to just run as a daemon on the server).

Kind regards, Warkst

EDIT:

I've tried some things described here: Java Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable

You need to specify the -Djava.awt.headless=true parameter at startup time.

(Assuming I'm doing it right with the command java -Djava.awt.headless=true -jar MyApp.jar), this yielded no results (the same errors occur).

export DISPLAY=:0

Still no result, though the error obviously changed slightly to now read:

(java:30765): Gtk-WARNING **: cannot open display: :0

Then finally I also tried the following:

unset DISPLAY

This resulted in the original error (where obviously DISPLAY was not set).

Contributor answered 16/1, 2014 at 12:53 Comment(0)
E
4

I don't think JavaFX 2.x supports running in a headless mode. I don't know of any workaround.

For further info see the JavaFX issue tracker feature request: RT-34241 Use of WebEngine in a headless system, currently scheduled for implementation for Java 9.

Emboly answered 16/1, 2014 at 13:20 Comment(1)
Though that is unfortunate news, thank you for the reply, I believe this answers my question.Contributor
L
4

I had almost the same problem

Failed in XOpenDisplay
(java:2593): Gtk-WARNING **: cannot open display:

while running unit tests for my JavaFX application in headless Ubuntu docker container on Travis CI.

The solution is installing X Virtual Framebuffer (xvfb) in the container to imitate a display presents via the container configuration change in .travis.yml

before_script:
  - "export DISPLAY=:99.0"
  - "sh -e /etc/init.d/xvfb start"
  - sleep 3 # give xvfb some time to start

This allows JavaFX successfully initialize it's core and create JavaFX components without actually showing them on screen.

See details of this solution in article Using xvfb to Run Tests That Require a GUI

Language answered 9/6, 2016 at 21:29 Comment(2)
Why is this downvoted? Does this not work? This solution seems completely reasonable.Affinity
+1 because it's a great option. I doubt this will be universal for all of Linux. I'm deploying for RHEL/Centos and have the same problem. I had a similar problem with matplotlib and worked around it with hacky code. Maybe a generalization of this will help? I'm using JFX next... :(Resendez
B
0

Running dbus-update-activation-environment --systemd DISPLAY XAUTHORITY in that shell before launching the UI app fixed this issue for me.

Boarfish answered 13/10, 2022 at 19:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.