Support GUI modeCLI mode switching with Java and Shell scripts

xiaoxiao2021-03-05  24

In UNIX / Linux systems, using Java development GUI programs, the most common problem is the availability problem of graphical interfaces. Programmers typically want to display the GUI interface to the user. However, in the UNIX world, it is not supported by GUI (especially X-Windows), which may include the following points:

1. Display variable does not set or set an error

2. The client does not support x-windows (such as Windows Telnet)

3. Failure to have enough permissions (Xhost did not give sufficient permissions)

In order to solve this problem, you can freely switch the GUI interface and the CLI interface through UNIX, and to use the GUI interface to use the GUI interface, where the GUI interface is not displayed, the purpose of the CLI interface is displayed. More articles, please visit

Www.javashelf.com.cn.

The following Bash code shows the use of XDPYINFO.

Echo $ * | egrep -e "/ -nodisplay"> / dev / null

IF [$? -eq 0]; then

Unset Display

EXTRA_JVM_OPTIONS = "- Djava.awt.Headless = True $ extra_jvm_options"

Export extra_jvm_options

Else

XDPYINFO> / DEV / NULL 2> & 1

IF [$? -ne 0]; then

Unset Display

EXTRA_JVM_OPTIONS = "- Djava.awt.Headless = True $ extra_jvm_options"

Export extra_jvm_options

Save_args = $ *

SET - "$ save_args -nodisplay"

Fi

Fi

Java my_class $ save_args

In the above example, XDPYINFO is used to detect whether the current environment supports x-windows. If the current environment supports X-Windows, XDPYInfo will return the current X-Windows configuration. If the current environment does not support x-windows, xdpyInfo will report an error. By detecting the result of xdpyInfo, you can learn whether the current environment supports X-Windows. If X-Windows is not supported, you can join the -NodisPlay parameter to the parameter list that is incoming Java. Thus, as long as in the Java program, detect if the Java incoming parameter has a -NODISPLAY parameter, you can switch whether the GUI interface or the CLI interface is switched.

转载请注明原文地址:https://www.9cbs.com/read-32292.html

New Post(0)