欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Linux/Unix下JFreeChart的NoClassDefFoundError问题

程序员文章站 2024-01-23 18:47:28
...

最近遇到这样一个问题,使用JFreechart 1.0.13开发的程序,在Windows上正常运行,到Linux下就莫名其妙的报错了,查看log,出现了

 

Caused by: java.lang.NoClassDefFoundError
    at org.jfree.chart.ChartFactory.createBarChart...

一般的出现NoClassDefFoundError,都是因为缺少Java Class的依赖,而且会提示缺少的Class名字,这个就比较怪了,这里我们看看如何处理这类的问题。

出错原因

Google一下

java.lang.NoClassDefFoundError

at org.jfree.chart.ChartFactory.createBarChart

发现在http://www.jfree.org/上很多人都有这个问题,而且都出现在Linux或者Unix系统上,原来这是一个Linux/Unix下Java的问题。详细见:http://www.jfree.org/phpBB2/viewtopic.php?t=8420

 写道
-------------------------------------------------------------------------------

10. My web application runs fine on my Windows development machine, but when
I deploy it to the Unix/Linux production server, it doesn't work. What
is the problem?

Most likely your server does not have X11 running. This is a Java
(AWT/Java2D) issue, not something that is specific to JFreeChart. There is
some more information at Sun's website:

http://java.sun.com/products/java-media/2D/forDevelopers/java2dfaq.html#xvfb

In addition, the following thread in the JFreeChart forum contains some
useful information:

http://www.jfree.org/phpBB2/viewtopic.php?t=1012

-------------------------------------------------------------------------------

这里给出了问题的详细链接,以及解决方案。

解决方案

1,如果是Tomcat等Web server中的app,遇到这个问题,可以尝试修改tomcat的启动配置,添加如下的Java的参数:

-Djava.awt.headless = true

一般在%TomcatHome%\bin\catalina.bat文件中设置

set JAVA_OPTS=%JAVA_OPTS%  -Djava.awt.headless = true

不过很可惜,测试没有作用,依然出错。可能是哪里出了问题。

 

2,在应用程序中添加Java属性设置:

System.setProperty("java.awt.headless","true")

测试生效!

 

本文同步发表在 http://www.xeclipse.com/?p=1287

相关标签: Java JFreeChart