Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top