Linux上 Can't connect to X11 window server Exception解决方法

  • 2018-04-02
  • 浏览 (446)

做了一个图片验证码功能,在windows上正常,linux上就错误

Exception in thread "main" 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.<clinit>(X11GraphicsEnvironment.java:134)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
at java.awt.Font.initializeFont(Font.java:308)
at java.awt.Font.<init>(Font.java:344)
at org.jfree.chart.axis.AxisConstants.<clinit>(Unknown Source)
at org.jfree.chart.axis.Axis.<init>(Unknown Source)
at org.jfree.chart.axis.CategoryAxis.<init>(Unknown Source)
at org.jfree.chart.ChartFactory.createLineChart(Unknown Source)


原因是windows内核集成了gui,而linux上没有启动x server

解决办法:

1、启动x server再启动tomcat

2、修改tomcat的startup.sh

加入export CATALINA_OPTS="-Djava.awt.headless=true"

init 3启动级别下,这种方式可以解决java awt的问题。
正文到此结束