Starting X Server in Headless Linux

JxBrowser library can be used in the headless Linux environment, given the X server is running.

Here is how to start the X Server:

1. Install Xvfb server

in your headless Linux, e.g. Ubuntu Server 16.04.2 LTS:

sudo apt-get install xvfb

2. Start the X Server

using the following command:

Xvfb :1 -screen 0 800x600x16

3. Run your Java application

If your application is packaged in a jar file, the arguments of the xvfb-run command would look like this:

xvfb-run java -jar yourApplication.jar

What about the “headless” flag?

Chromium 58 and higher support the --headless command line flag which works for Linux only.

The flag allows to run Chromium in Linux headless environment without starting the X server. This flag is designed for the case when you just need to run Chromium in headless environment, load some URL, and attach to the loaded web page using DevTools via the --remote-debugging-port switcher. For example:

chrome --headless --remote-debugging-port=9222 https://chromium.org

In such case you load the localhost:9222 web page in a web browser application and work with the loaded web page using DevTools.

As you can see, the --headless command line flag is designed to be used when you need to load a single web page and work with it via DevTools. We checked Chromium’s source code and figured out that this flag forces Chromium to use a separate, limited version of the Chromium API that does not support most (~80-90%) of the features used in JxBrowser.

It means that this flag disables most of the JxBrowser functionality, such as loading different web pages by URL, HTML, navigating backward and forward, executing JavaScript, etc.

This is why this flag is NOT supported by JxBrowser, and we recommend you to start the X server in order to use JxBrowser in a headless Linux environment.

Go Top