Note: Advice in this article will only work for JxBrowser 6. See the corresponding article for JxBrowser 7 here.(注意:本文中的建议仅适用于JxBrowser6,JxBrowser7相应文章请点击这里。)

JxBrowser library can be used in the headless Linux environments. To achieve that, the X-Server must be started.(JxBrowser库可以在无头Linux环境中使用。为此,必须启动X-server。)

In order to start X-Server, you need to perform the following actions:(为了启动X-Server,您需要执行以下操作:)

1. Install Xvfb server in your headless Linux (e.g. Ubuntu Server 16.04.2 LTS):(1.在无头Linux中安装Xvfb服务器(例如Ubuntu Server 16.04.2 LTS):)

sudo apt-get install xvfb

2. Start X-Server using the following command:(2.使用以下命令启动X-Server:)

Xvfb :1 -screen 0 800x600x16

3. Run your Java application, e.g. packed in the jar file, using the xvfb-run command:(3.运行您的Java应用程序,例如使用xvfb-run命令打包在jar文件中:)

xvfb-run java -jar yourApplication.jar

What about the --headless command line flag?(--headless命令行标志呢?)

Chromium 58 and higher supports the --headless command line flag (Linux-only) that allows you to run Chromium in Linux headless environment without starting 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:(Chromium 58及更高版本支持--headless命令行标志(仅Linux),该标志允许您在Linux无头环境中运行Chromium,而无需启动X-Server。此标志是为仅在无头环境中运行Chromium,加载一些URL并通过--remote-debugging-port切换器使用DevTools附加到加载的网页的情况而设计的。例如:)

$ chrome --headless --remote-debugging-port=9222

Then, you load the localhost:9222 web page in a web browser application and work with the loaded web page using DevTools.(然后,您在Web浏览器应用程序中加载localhost:9222网页,并使用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 the Chromium API that doesn't support ~80-90% of the features used in JxBrowser. It means that this flag disables ~80-90% of JxBrowser functionality such as loading different web pages by URL, HTML, navigating backward, forward, executing JavaScript, etc. This is why this flag isn't supported by JxBrowser and we recommend that you start X-Server to use JxBrowser in a headless Linux environment.(如您所见,--headless命令行标志设计用于需要加载单个网页并通过DevTools使用它的情况。我们检查了Chromium的源代码,发现该标志迫使Chromium使用单独的有限版本的Chromium API,该API不支持JxBrowser中使用的功能的80%到90%。这意味着该标志会禁用约80-90%的JxBrowser功能,例如通过URL,HTML加载不同的网页,向后导航,前进,执行JavaScript等。这就是JxBrowser不支持此标志的原因,我们建议您您启动X-Server在无头Linux环境中使用JxBrowser。)