how can i use jfreechart in linux correctly
how can i use jfreechart in linux correctly
i want to use jfreechart in web program in linux .the web server is tomcat .
the version of jfreechart is latest one 0.9.20.
i wrote one simple test example.
package netmatrix;
import java.io.*;
import java.awt.Insets;
import java.awt.Font;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.Locale;
import java.text.NumberFormat;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jfree.data.*;
import org.jfree.chart.*;
import org.jfree.chart.axis.*;
import org.jfree.chart.renderer.StandardXYItemRenderer;
import org.jfree.chart.plot.*;
import org.jfree.chart.entity.*;
import org.jfree.chart.urls.*;
import org.jfree.chart.servlet.*;
import org.jfree.chart.title.TextTitle;
import java.net.URL;
public class ImagShow {
public String getimageurl(HttpServletRequest request,HttpServletResponse response) {
String titleStr = "test";
String filename = null;
Font font;
try {
font = new Font(null, Font.CENTER_BASELINE, 20);
PiePlot plot = new PiePlot(getdataset());
plot.setInsets(new Insets(0, 5, 5, 5));
JFreeChart chart = new JFreeChart("",font,plot, true);
TextTitle title = new TextTitle(titleStr);
chart.setTitle(title);
title.setFont(font);
chart.setBackgroundPaint(java.awt.Color.white);
HttpSession session = request.getSession();
filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, session);
ServletUtilities.sendTempFile(filename, response);
return request.getContextPath() + "/servlet/DisplayChart?filename=" +filename;
}catch (Exception ex) {
System.out.print(ex.fillInStackTrace());
}
return null;
}
private DefaultPieDataset getdataset() {
DefaultPieDataset data = new DefaultPieDataset();
data.setValue("test1", 2000);
data.setValue("test2", 400);
data.setValue("test3", 100);
return data;
}
}
and a jsp file
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import = "netmatrix.*"%>
<%ImagShow imgshow =new ImagShow ();%>
<img src="<%= imgshow.getimageurl(request,response) %>" width=500 height=300 border=0 >
but every time ,i visit the jsp page from IE,the Exception is thrown root cause
java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:125)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:140)
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
java.awt.Font.initializeFont(Font.java:303)
java.awt.Font.<init>(Font.java:339)
org.jfree.chart.plot.PiePlot.<clinit>(PiePlot.java:186)
netmatrix.ImagShow.getimageurl(ImagShow.java:32)
org.apache.jsp.jsp.jfreetest2_jsp._jspService(jfreetest2_jsp.java:47)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
and if I refresh the page,anthoer exception is thrown
root cause
java.lang.NoClassDefFoundError
netmatrix.ImagShow.getimageurl(ImagShow.java:32)
org.apache.jsp.jsp.jfreetest2_jsp._jspService(jfreetest2_jsp.java:47)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
my web server is tomcat,and i have put the jfreechart.jar jcommon.jar to /project/WEB-INF/lib directory.
then my question:
what I should do next
and what confuse more is, that i install tomcat in windows platform ,jfreechart can work correctly.
who can tell me why.
thanks!
the version of jfreechart is latest one 0.9.20.
i wrote one simple test example.
package netmatrix;
import java.io.*;
import java.awt.Insets;
import java.awt.Font;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.Locale;
import java.text.NumberFormat;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jfree.data.*;
import org.jfree.chart.*;
import org.jfree.chart.axis.*;
import org.jfree.chart.renderer.StandardXYItemRenderer;
import org.jfree.chart.plot.*;
import org.jfree.chart.entity.*;
import org.jfree.chart.urls.*;
import org.jfree.chart.servlet.*;
import org.jfree.chart.title.TextTitle;
import java.net.URL;
public class ImagShow {
public String getimageurl(HttpServletRequest request,HttpServletResponse response) {
String titleStr = "test";
String filename = null;
Font font;
try {
font = new Font(null, Font.CENTER_BASELINE, 20);
PiePlot plot = new PiePlot(getdataset());
plot.setInsets(new Insets(0, 5, 5, 5));
JFreeChart chart = new JFreeChart("",font,plot, true);
TextTitle title = new TextTitle(titleStr);
chart.setTitle(title);
title.setFont(font);
chart.setBackgroundPaint(java.awt.Color.white);
HttpSession session = request.getSession();
filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, session);
ServletUtilities.sendTempFile(filename, response);
return request.getContextPath() + "/servlet/DisplayChart?filename=" +filename;
}catch (Exception ex) {
System.out.print(ex.fillInStackTrace());
}
return null;
}
private DefaultPieDataset getdataset() {
DefaultPieDataset data = new DefaultPieDataset();
data.setValue("test1", 2000);
data.setValue("test2", 400);
data.setValue("test3", 100);
return data;
}
}
and a jsp file
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import = "netmatrix.*"%>
<%ImagShow imgshow =new ImagShow ();%>
<img src="<%= imgshow.getimageurl(request,response) %>" width=500 height=300 border=0 >
but every time ,i visit the jsp page from IE,the Exception is thrown root cause
java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:125)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Class.java:140)
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
java.awt.Font.initializeFont(Font.java:303)
java.awt.Font.<init>(Font.java:339)
org.jfree.chart.plot.PiePlot.<clinit>(PiePlot.java:186)
netmatrix.ImagShow.getimageurl(ImagShow.java:32)
org.apache.jsp.jsp.jfreetest2_jsp._jspService(jfreetest2_jsp.java:47)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
and if I refresh the page,anthoer exception is thrown
root cause
java.lang.NoClassDefFoundError
netmatrix.ImagShow.getimageurl(ImagShow.java:32)
org.apache.jsp.jsp.jfreetest2_jsp._jspService(jfreetest2_jsp.java:47)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
my web server is tomcat,and i have put the jfreechart.jar jcommon.jar to /project/WEB-INF/lib directory.
then my question:
what I should do next
and what confuse more is, that i install tomcat in windows platform ,jfreechart can work correctly.
who can tell me why.
thanks!
Okay, what you first should verify are the Java Classpath etc. Java_Home
Catalina_Home etc. make sure you have all Environment variables set corretctly.
if you're lucky the only problem is that a class-file cannot be found, like the error message says
Like in your other post you should first try to get the Sample.war running and after it runs you should try your app.
To the display variable under linux I can't help you much, because I just know it has to be set correctly...
You should also verify you J2SE (1.4.1) or different Version is installed correctly with all env. Vars set.
Check under which user you start Tomcat etc. maybe the user you are using has no right to read the lib path of Tomcat or the path of java/lib ... etc.
I hope this helps a little, we got tomcat an JFreeChart working under AIX, but with IBM Java
The last idea i can give you:
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
these three nee J2EE not J2SE... Servlet etc. is only in the J2EE but since the jar comes with tomcat I'm not sure if you need it, I used jsp only for presentation part the rest of my app is compliled by javac so I can tell javac to use /tomcat/.../lib/servlet.jar ...
Catalina_Home etc. make sure you have all Environment variables set corretctly.
if you're lucky the only problem is that a class-file cannot be found, like the error message says

Like in your other post you should first try to get the Sample.war running and after it runs you should try your app.
To the display variable under linux I can't help you much, because I just know it has to be set correctly...
You should also verify you J2SE (1.4.1) or different Version is installed correctly with all env. Vars set.
Check under which user you start Tomcat etc. maybe the user you are using has no right to read the lib path of Tomcat or the path of java/lib ... etc.
I hope this helps a little, we got tomcat an JFreeChart working under AIX, but with IBM Java

The last idea i can give you:
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
these three nee J2EE not J2SE... Servlet etc. is only in the J2EE but since the jar comes with tomcat I'm not sure if you need it, I used jsp only for presentation part the rest of my app is compliled by javac so I can tell javac to use /tomcat/.../lib/servlet.jar ...
It's on the forum at the very top called "FREQUENTLY ASKED QUESTIONS"
http://www.jfree.org/phpBB2/viewtopic.php?t=8420
Nicky
http://www.jfree.org/phpBB2/viewtopic.php?t=8420
Nicky
thanks for your comments and FAQ.
I edit the catalina.sh ,add one line "export CATALINA_OPTS="-Djava.awt.headless=true" .
then when i visit the page , the first exception(java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable) is not thrown,but the second exception(java.lang.NoClassDefFoundError ) is still thrown.
IS tomcat find the class from classpath
what I have done include
1.add the jfreechart.jar,jcommon.jar to classpath
2. put the two jar file into [project-virtual-directory]/web-inf/lib
3. put the two jar file into [tomcat-home]/common/lib
4.also put the two jar file into [java-home]/jre/lib/ext
as far as I know, tomcat find the class from these three directory.
I have done what I can do, but it still not work, so help people ,warmhearted man
I edit the catalina.sh ,add one line "export CATALINA_OPTS="-Djava.awt.headless=true" .
then when i visit the page , the first exception(java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable) is not thrown,but the second exception(java.lang.NoClassDefFoundError ) is still thrown.
IS tomcat find the class from classpath
what I have done include
1.add the jfreechart.jar,jcommon.jar to classpath
2. put the two jar file into [project-virtual-directory]/web-inf/lib
3. put the two jar file into [tomcat-home]/common/lib
4.also put the two jar file into [java-home]/jre/lib/ext
as far as I know, tomcat find the class from these three directory.
I have done what I can do, but it still not work, so help people ,warmhearted man
no ,only one jar in my classpath.
/usr/local/j2sdk1.4.1/jre/lib/charsets.jar:/usr/local/j2sdk1.4.1/lib/tools.jar:/usr/local/j2sdk1.4.1/jre/lib/rt.jar:/usr/local/j2sdk1.4.1/lib/dt.jar:/usr/local/j2sdk1.4.1/jre/lib/ext/mssqlserver.jar:/usr/local/j2sdk1.4.1/jre/lib/ext/msbase.jar:/usr/local/j2sdk1.4.1/jre/lib/ext/msutil.jar:/usr/local/tomcat/common/lib/servlet-api.jar:.:/home/violin/software/tomcat/jakarta-tomcat-5.0.18/common/lib/jfreechart-0.9.20.jar:/home/violin/software/tomcat/jakarta-tomcat-5.0.18/common/lib/jcommon-0.9.3.jar
does tomcat find class from classpath or tomcat find class from serval specific directory ,just as [tomcat-home]/common/lib?
i am looking forward to further reply
/usr/local/j2sdk1.4.1/jre/lib/charsets.jar:/usr/local/j2sdk1.4.1/lib/tools.jar:/usr/local/j2sdk1.4.1/jre/lib/rt.jar:/usr/local/j2sdk1.4.1/lib/dt.jar:/usr/local/j2sdk1.4.1/jre/lib/ext/mssqlserver.jar:/usr/local/j2sdk1.4.1/jre/lib/ext/msbase.jar:/usr/local/j2sdk1.4.1/jre/lib/ext/msutil.jar:/usr/local/tomcat/common/lib/servlet-api.jar:.:/home/violin/software/tomcat/jakarta-tomcat-5.0.18/common/lib/jfreechart-0.9.20.jar:/home/violin/software/tomcat/jakarta-tomcat-5.0.18/common/lib/jcommon-0.9.3.jar
does tomcat find class from classpath or tomcat find class from serval specific directory ,just as [tomcat-home]/common/lib?
i am looking forward to further reply