Error: xshell remote connection or local Linux OS start Java program error:
no X11 display variable was set,
or can’t connect to X11 window server using ‘: 1.0’as the value of the display variable
Error details:
[root@neokylinimport_jre]#./run_linux64
/root/lyy/import_jre
/root/lyy/import_jre/lib
/root/lyy/import_jre/jre8_openjdk64/bin
classpathis:/root/lyy/import_jre/lib/myapp.jar:/root/lyy/import_jre/jre8_openjdk64/lib/ext:/root/lyy/import_jre/lib/lib/commons-io-2.0.1.jar:/root/lyy/import_jre/lib/lib/dom4j-1.6.1.jar:/root/lyy/import_jre/lib/lib/hgdb-1.3-jdbc41.jar:/root/lyy/import_jre/lib/lib/log4j-1.2.17.jar:/root/lyy/import_jre/lib/lib/poi4excel.jar:/root/lyy/import_jre/lib/lib/slf4j-api-1.7.2.jar:/root/lyy/import_jre/lib/lib/slf4j-log4j12-1.7.2.jar
runnow...
Noprotocolspecified
Exceptioninthread"main"java.awt.AWTError:Can'tconnecttoX11windowserverusing':1.0'asthevalueoftheDISPLAYvariable.
atsun.awt.X11GraphicsEnvironment.initDisplay(NativeMethod)
atsun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:66)
atsun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:187)
atjava.security.AccessController.doPrivileged(NativeMethod)
atsun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:146)
atjava.lang.Class.forName0(NativeMethod)
atjava.lang.Class.forName(Class.java:260)
atjava.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:102)
atjava.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
atsun.awt.X11.XToolkit.<clinit>(XToolkit.java:123)
atjava.lang.Class.forName0(NativeMethod)
atjava.lang.Class.forName(Class.java:260)
atjava.awt.Toolkit$2.run(Toolkit.java:860)
atjava.awt.Toolkit$2.run(Toolkit.java:855)
atjava.security.AccessController.doPrivileged(NativeMethod)
atjava.awt.Toolkit.getDefaultToolkit(Toolkit.java:854)
atjavax.swing.UIManager.getSystemLookAndFeelClassName(UIManager.java:611)
athgdbmonitor.view.MonitorView.main(MonitorView.java:2147)
Error reason: when looking for errors, we should see the error prompt can’t connect to X11 window server using ‘: 1.0’ as the value of the display variable
analysis:
1. By querying, we know that Linux starts X11 windows server by default, and it is related to the graphical tool display of windows
2. The value of the variable display is related to which graphical terminal of the machine the program interface is displayed on. By executing who command and who AMI command, you can know that the current graphical terminal is the nth (the following is the second). Then the value of the variable display (the value format is I P: A.B, where B is 0 by default) should be IP: (n-1) or: (n-1)
solution 1 :
first, make sure that the server SSH settings are configured as x11forward yes
reference: xshell: https://www.netsarang.com/tutorial/xshell/1018/Using_ X11_ forwarding
vi /etc/ssh/sshd_ Configure: x11forward yes
and restart service sshd restart
Then make sure the xshell client is configured as:
properties connection SSH tunnel:
X11 transfer – (checked) forward X11 connection to – (checked) xmanager
Then open the xshell session:
echo $display view is valuable
at this time, run the script directly to open the GUI interface of the program
solution 2 :
When the display environment variable is not automatically generated, set it manually
Local setting:
export display =: 0.0
Remote setting:
who
who AMI
determine the specific value of X according to the result
export display= localhost:x.0
Note: the value of the variable display is related to which graphical terminal of the machine the program interface is displayed on. By executing the who command and who AMI command, you can know that the current graphical terminal is the nth (as follows: the second). Then the value of the variable display (IP: A.B, where B is 0 by default) should be IP: (n-1) or: (n-1) (as follows: 1.0), Only in this way can the interface of Java graphic program be displayed normally
[root@neokylinimport_jre]#who
roottty22015-02-0613:18
rootpts/12015-02-0613:42(192.168.100.126)
highgopts/22015-02-0613:42(:1.0)
[root@neokylinimport_jre]#whoami
highgopts/22015-02-0613:42(:1.0)
[root@neokylinimport_jre]#echo$DISPLAY
:1.0
If the value of display does not match, you can ask the administrator of the machine to check whether the machine is turned on normally, or ask the visitor of other graphics terminal to turn off remote desktop access, only keep your remote desktop, and then try to execute the program again
References: http://www.itpub.net/thread-1633000-1-1.html