Can't connect to X11 window server

这两天遇到几个十分之龌龊的问题,真不明白IBM AIX这种操作系统为什么还这么多人使用。

问题都是出在AIX上,现象是页面始终在加载,图片无法生成。
首先为保证关闭Xmanager终端后,后台服务不被停止,必须使用『nohup &』启动命令。
但是有时候即使nohup也不能保证服务不被停止,其它目录如screen又没有,找来找去只好先正常启动服务,然后ps出进程号,再执行『nobup -p processNumber』。
之后就是只要是nohup的服务页面都会始终加载,要么报错浏览器已不响应。
后台异常看不到,估计是被吃掉了。只要监控前台的HttpResponse流,截取出错误堆栈,主要错误如下:

org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError: sun.awt.X11GraphicsEnvironment (initialization failure)
org.jboss.resteasy.core.SynchronousDispatcher.unwrapException(SynchronousDispatcher.java:329)
org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:305)
org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:198)
org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:174)
org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:518)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:480)
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:207)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause: java.lang.NoClassDefFoundError: sun.awt.X11GraphicsEnvironment (initialization failure)
java.lang.J9VMInternals.initialize(J9VMInternals.java:140)
java.lang.Class.forNameImpl(Native Method)
java.lang.Class.forName(Class.java:136)
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1146)
java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1136)
root cause:java.lang.InternalError: Can't connect to X11 window server using '10.0.51.81:0.0' as the value of the DISPLAY variable.
sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
sun.awt.X11GraphicsEnvironment.access$100(X11GraphicsEnvironment.java:52)
sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:155)
java.security.AccessController.doPrivileged(AccessController.java:202)
sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:131)
java.lang.J9VMInternals.initializeImpl(Native Method)
java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
java.lang.Class.forNameImpl(Native Method)
java.lang.Class.forName(Class.java:136)
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
sun.awt.X11.XToolkit.<clinit>(XToolkit.java:89)
java.lang.J9VMInternals.initializeImpl(Native Method)
java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
java.lang.Class.forNameImpl(Native Method)
java.lang.Class.forName(Class.java:136)
java.awt.Toolkit$2.run(Toolkit.java:845)
java.security.AccessController.doPrivileged(AccessController.java:202)
java.awt.Toolkit.getDefaultToolkit(Toolkit.java:837)
`

最终通过在java命令行中加入如下参数解决问题:

-Djava.awt.headless=true

参考阅读
Can’t connect to X11 window server using ‘:0.0’ as the value of the DISPLAY variable

评论