NoClassDefFoundError when ChartFactory.createXYLineChart
NoClassDefFoundError when ChartFactory.createXYLineChart
Hi, when executing a servlet that generates a chart I get the exception shown below. It's a java.lang.NoClassDefFoundError, but it does not specify which class it's not understanding. The version of jfreechart I'm using is 0.9.21 with jcommon 0.9.6, and the servlet is running on tomcat 3.3 (yes really old, but migration to a newer version is not possible right now, the application just stops working). The piece of code that causes the exception is:
JFreeChart chart =
ChartFactory.createXYLineChart("Demanda",
"Horas", "Nm3/hora", dataset,
PlotOrientation.VERTICAL,
true,true,false);
Any hint will be appreciated.
Thanks,
alvarbar
java.lang.NoClassDefFoundError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:58)
at java.awt.Font.initializeFont(Font.java:264)
at java.awt.Font.<init>(Font.java:298)
at org.jfree.chart.axis.Axis.<clinit>(Axis.java:113)
at org.jfree.chart.ChartFactory.createXYLineChart(ChartFactory.java:1285)
at com.enagas.web.grafico.DemandaGrafico.crearChart(DemandaGrafico.java:76)
at com.enagas.web.grafico.DemandaGrafico.doGet(DemandaGrafico.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:484)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:432)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Ajp13Interceptor.processConnection(Ajp13Interceptor.java:213)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:477)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:519)
at java.lang.Thread.run(Thread.java:484)
JFreeChart chart =
ChartFactory.createXYLineChart("Demanda",
"Horas", "Nm3/hora", dataset,
PlotOrientation.VERTICAL,
true,true,false);
Any hint will be appreciated.
Thanks,
alvarbar
java.lang.NoClassDefFoundError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:58)
at java.awt.Font.initializeFont(Font.java:264)
at java.awt.Font.<init>(Font.java:298)
at org.jfree.chart.axis.Axis.<clinit>(Axis.java:113)
at org.jfree.chart.ChartFactory.createXYLineChart(ChartFactory.java:1285)
at com.enagas.web.grafico.DemandaGrafico.crearChart(DemandaGrafico.java:76)
at com.enagas.web.grafico.DemandaGrafico.doGet(DemandaGrafico.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:484)
at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
at org.apache.tomcat.core.Handler.service(Handler.java:235)
at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:432)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Ajp13Interceptor.processConnection(Ajp13Interceptor.java:213)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:477)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:519)
at java.lang.Thread.run(Thread.java:484)
-
- Posts: 15
- Joined: Fri Oct 07, 2005 2:32 pm
Since the exception trace alerts:
at org.jfree.chart.ChartFactory.createXYLineChart(ChartFactory.java:1285)
I've searched thru the source code what happens in line 1285 of ChartFactory. That line is within the method createXYLineChart and it just instantiates a NumberAxis object:
NumberAxis xAxis = new NumberAxis(xAxisLabel);
This object is definitely included in the jar so I don´t know what else may work wrong.
Well, I'll try another version, but I don´t think is a version problem. Actually the application is drawing the graph fine in other computer with same version of tomcat and same version of jdk1.3.1 installed.
at org.jfree.chart.ChartFactory.createXYLineChart(ChartFactory.java:1285)
I've searched thru the source code what happens in line 1285 of ChartFactory. That line is within the method createXYLineChart and it just instantiates a NumberAxis object:
NumberAxis xAxis = new NumberAxis(xAxisLabel);
This object is definitely included in the jar so I don´t know what else may work wrong.
Well, I'll try another version, but I don´t think is a version problem. Actually the application is drawing the graph fine in other computer with same version of tomcat and same version of jdk1.3.1 installed.
-
- Posts: 15
- Joined: Fri Oct 07, 2005 2:32 pm
Re: NoClassDefFoundError when ChartFactory.createXYLineChart
I just had the same problem when running on Linux. After spending an evening on this, I'd like to share my findings. There are three solutions I found:
1) If you don't need user interaction, e.g. just need to generate an image for a web application, you can run headless. So, set the java system property: java -Djava.awt.headless=true, can also be set inside the java code. Please refer to: http://java.sun.com/developer/technical ... /headless/ and make sure you don't use any of the mentioned classes.
2) Java 5 has a bug with locating its shared libraries. If you need to use JDK1.5, add $JAVA_HOME/lib/i386 to $LD_LIBRARY_PATH, e.g. setenv LD_LIBRARY_PATH {$JAVA_HOME/lib/i386:$LD_LIBRARY_PATH}.
3) Upgrade to Java 6.
Since my code has user interaction, the first solution didn't work (received HeadlessException of couse), but the other two work great.
Hope someone will find this helpful.
1) If you don't need user interaction, e.g. just need to generate an image for a web application, you can run headless. So, set the java system property: java -Djava.awt.headless=true, can also be set inside the java code. Please refer to: http://java.sun.com/developer/technical ... /headless/ and make sure you don't use any of the mentioned classes.
2) Java 5 has a bug with locating its shared libraries. If you need to use JDK1.5, add $JAVA_HOME/lib/i386 to $LD_LIBRARY_PATH, e.g. setenv LD_LIBRARY_PATH {$JAVA_HOME/lib/i386:$LD_LIBRARY_PATH}.
3) Upgrade to Java 6.
Since my code has user interaction, the first solution didn't work (received HeadlessException of couse), but the other two work great.
Hope someone will find this helpful.