Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFx in headless mode

Tags:

javafx

Is it possible to run JavaFx in headless mode(in Java 7)? It is being used to generate images on the server but is asking for an X-Server. Does there exist something like java.awt.headless in JavaFx ?(I can't use Xvfb )

like image 350
Tinku Avatar asked Nov 29 '13 06:11

Tinku


3 Answers

Here is how I solved this problem for server-side image geneartion on Ubuntu linux environment with jetty application server. It uses xvfb but only as a "library" - without any additional special actions on server:

apt-get install xvfb

// then on application server start:

export DISPLAY=":99"

start-stop-daemon --start --background --user jetty --exec "/usr/bin/sudo" -- -u jetty /usr/bin/Xvfb :99 -screen 0 1024x768x24

You can see the details of my server-side image generation solution in this SO question.

like image 63
Nailgun Avatar answered Oct 31 '22 10:10

Nailgun


This is a kind of problem which I encountered while capturing images in Mac OS.

I have solved this issue by using

static {

        System.setProperty("java.awt.headless", "false");
}

See for reference : Headless environment error in java.awt.Robot class with MAC OS

like image 20
Shreyas Dave Avatar answered Oct 31 '22 12:10

Shreyas Dave


Answer by Shreyas Dave didn't work for me anymore. Though I don't know why, here is what I did:

public static void main(String[] args) {
    // to avoid
    // [JRSAppKitAWT markAppIsDaemon]: Process manager already initialized: can't fully enable headless mode.
    System.setProperty("javafx.macosx.embedded", "true");
    java.awt.Toolkit.getDefaultToolkit();
    // end
    launch(args);
}

This was also pointed out here: JavaFX screencapture headless exception on OSX

like image 37
angabriel Avatar answered Oct 31 '22 11:10

angabriel