jfreechart圖表在windows上運行正常,但在linux上運行出錯如下:
java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:134)
在網上查到:
“這個錯誤是因為圖表程式是通過AWT實現的,AWT會叫用作業系統本地視窗資源繪圖,windows對此支援很好,在linux下如果沒有進到X window,AWT就不能繪圖”
解決辦法:
[root@localhost logs]# export DISPLAY=:0
[root@localhost logs]# source /etc/profile
[root@localhost logs]# env
看到
DISPLAY=:0
表示設定ok。重起tomcat服務就可以了。
---------------------------------------------------------
看到一些網友的做法,自己未曾驗證過:
jasper安裝在windows環境運行正常,但是在linux環境中出現錯誤:java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
解決方式:
在JVM中加入-Djava.awt.headless=true
對於tomcat ,可以修改catalina.sh,加入CATALINA_OPTS="$CATALINA_OPTS -Djava.awt.headless=true "
如:
......
elif [ "" = "start" ] ; then
shift
touch "$CATALINA_BASE"/logs/catalina.out
CATALINA_OPTS="$CATALINA_OPTS -Djava.awt.headless=true" ##在catalina.sh檔案(240行後添加此行)
if [ "" = "-security" ] ; then
echo "Using Security Manager"
shift
.....
=======================
官方問題解決:http://www.jfree.org/jfreechart/faq.html#FAQ10
請參考:
http://www.cnflex.org/bbs/archiver/?tid-1.html
Linux 使用者要安裝xorg-x11-deprecated-libs包 (Fedora) 獲類似支援包以避免如下錯誤:
java.lang.UnsatisfiedLinkError: /opt/j2sdk1.4.2_11/jre/lib/i386/libawt.so: libXp.so.6: cannot open shared object file: No such file or directory
可用rpm -q xorg-x11-deprecated-libs 命令查看包資訊