jfreechart图表在linux上运行不显示


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 命令查看包信息

你可能感兴趣的:(jfreechart)