Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable.

剛剛在一臺Linux服務器上安裝了jdk和Tomcat,而後部署了一個web項目,在項目中有個添加圖片的功能,保存圖片時報錯java

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class javax.imageio.ImageIOlinux

web

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.UnsatisfiedLinkError: /home/software/jdk1.7.0_65/jre/lib/i386/xawt/libmawt.so: libXext.so.6: cannot open shared object file: No such file or directoryspring

網上說是jdk安裝了32位的,應該安裝64位的。而後我就將jdk刪除重裝了64位的。windows

如何查看jdk是多少位方法:tomcat

使用 java -version 便可。 
若是是安裝了32位的jdk,則輸出信息以下:服務器

java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot(TM) Server VM (build 25.144-b01, mixed mode)

上面的輸出信息中沒包含64bit。less

若是是安裝了64位的jdk,則輸出信息以下:post

java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

jdk由32位改成64位後,啓動項目,保存圖片時又報錯了,報錯信息以下ui

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11.XToolkit

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.InternalError: Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable.

百度了一下這個問題,基本上都說是以下緣由:

緣由是windows內核集成了gui,而linux上沒有啓動x server

解決辦法:
1。啓動x server

2。在java運行參數上加-Djava.awt.headless=true 

我修改了應用服務器的啓動文件。tomcat中的/bin/catalina.sh文件,
在全部的        -Dcatalina.home="$CATALINA_HOME" /下面都加上了               

                       -Djava.awt.headless=true /而後問題就解決了。

相關文章
相關標籤/搜索