验证码无法显示,服务器端出现异常:Could not initialize class sun.awt.X11GraphicsEnvironment

 异常信息:

    Caused by: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment

    Caused by: java.lang.InternalError: Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable.

验证码用到Java swt的类或方法,在windows系统开发运行正常,但是要部署到linux操作系统,特别是没有安装图形界面的X11,则会出现不支持的,显然关于图形的东西,硬件应该支持不了的,我们要的是客户端(Windows或有X11的linux系统)能够显示就行了。需要解决的是在tomcat的安装目录bin目录下catalina.sh文件的增加:

    -Djava.awt.headless=true

    

    类似于这个:

原文地址:https://www.cnblogs.com/wuxiang/p/7485037.html