远程启动的服务依赖显示环境导致java.awt.HeadlessException
服务器没有显示器,通过ssh登录启动的基于java的web服务,在java中有段生成缩略图的代码调用了Toolkit.getDefaultToolkit().getScreenResolution();,依赖显示环境
以下记录几个实验结果:
1、ssh user@ip之后,直接启动jetty.sh start,在生成缩略图时报错
java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it. at sun.awt.HeadlessToolkit.getScreenResolution(HeadlessToolkit.java:221)
这个解决办法:在ssh登录时加上 -X 选项
2、ssh -X user@ip 之后,设置-Djava.awt.headless=true,再启动jetty.sh start &,在生成缩略图时报错:
java.awt.HeadlessException at sun.awt.HeadlessToolkit.getScreenResolution(HeadlessToolkit.java:221)
3、ssh -X user@ip 之后,再启动jetty.sh start,没有问题
4、ssh -X user@ip 之后,设置-Djava.awt.headless=false,再启动jetty.sh start &,在生成缩略图时报错:
java.lang.InternalError: Can't connect to X11 window server using 'localhost:11.0' as the value of the DISPLAY variable. at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method) at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:62) at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:178) at java.security.AccessController.doPrivileged(Native Method) at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:142) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:186) at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82) at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:112) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:186) at java.awt.Toolkit$2.run(Toolkit.java:849) at java.security.AccessController.doPrivileged(Native Method) at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:841)
相关推荐
projava 2020-11-14
WanKaShing 2020-11-12
airfish000 2020-09-11
tryfind 2020-09-14
yegen00 2020-09-10
kkaazz 2020-09-03
风语者 2020-09-02
BraveWangDev 2020-08-19
lichuanlong00 2020-08-15
gsl 2020-08-15
pandaphinex 2020-08-09
yhuihon 2020-08-09
CheNorton 2020-08-02
xiangqiao 2020-07-28
hpujsj 2020-07-26
hpujsj 2020-07-26
sshong 2020-07-19
BraveWangDev 2020-07-19
annan 2020-07-18