jfreechart圖表在linux上運行不顯示

來源:互聯網
上載者:User
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 命令查看包資訊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.