Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy JavaFX on Ubuntu server without display

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).

like image 279
RDM Avatar asked Jan 16 '14 12:01

RDM


1 Answers

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.

like image 116
jewelsea Avatar answered Sep 19 '22 05:09

jewelsea