我们已经为Sybase服务器开发了基于Web的监视应用程序,并且在生产环境中使用jfree生成图形时遇到了问题。

我们通常在QA机器上构建和测试我们的应用程序,然后将构建的* .war文件通过ftp发送到生产环境。

当完全相同的代码片段无法在生产环境中生成图形时,在生产环境中就会出现问题。

以下是我们要导入的类和包:

package var;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.Format;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.axis.DateAxis;
import org.jfree.data.time.Minute;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;
import java.sql.DriverManager;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.sql.*;
import javax.naming.*;
import org.jfree.ui.RectangleInsets;
import java.awt.GraphicsEnvironment;


以下是我们认为会引发错误的代码段:

else
{
  int interval=Integer.parseInt(request.getParameter("interval").toString());
  System.out.println("I Before OS Level Object creation");
  OSLevel osl=new OSLevel();
  width=1500;
  height=500;
  XYDataset mdaDataSet=null;
  try
  {
  System.out.println("I Before XY Dataset generation");
  mdaDataSet=osl.generateXYDataSet(start, end, dval3, cpuval3, dsql3,interval);
  CategoryPlot plotmda = null;
  System.out.println("I Before Time Series generation");
  chartos = ChartFactory.createTimeSeriesChart(
          title, // chart title
          "Time", // domain axis label
          "CPU Usage Percentage", // range axis label
          mdaDataSet, // data
          true, // include legend
          true, // tooltips
          false // urls
          );
  System.out.println("The title is:"+title);
  }
  catch(Exception e)
  {
  System.out.println("I am in the Chart Generation TRY Block");
  e.printStackTrace();
  }


最后是质量检查中的server.log条目,然后是生产中的条目:

the query is:SELECT CPUUsed,DateTime FROM bureau.bp_mda_cpu WHERE (DateTime > '2013-07-11' and DateTime < '2013-07-18') and ClientID='G123'
I Before OS Level Object creation
I Before XY Dataset generation
I Before Time Series generation
The title is:MITSUBISHI_GLOSS Sybase CPU(MDA CPU report)
The File Path is:/tmp/tmpChart148725123563269780.tmp
END of the report



the query is:SELECT CPUUsed,DateTime FROM bureau.bp_mda_cpu WHERE (DateTime > '2013-07-11' and DateTime < '2013-07-18') and ClientID='G123'
I Before OS Level Object creation
I Before XY Dataset generation
I Before Time Series generation
Jul 18, 2013 9:52:07 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet GenerateDBReport threw exception
javax.servlet.ServletException: Servlet execution threw an exception
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:311)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:263)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1018)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:196)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:499)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
        at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1018)
        at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2748)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:186)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
        at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1018)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:512)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:562)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1018)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:199)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:637)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:463)
        at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:568)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:631)
        at java.lang.Thread.run(Thread.java:662)


稍微更改代码行后,出现以下新错误:

java.lang.NoClassDefFoundError: Could not initialize class org.jfree.chart.JFreeChart
        at org.jfree.chart.ChartFactory.createLineChart(ChartFactory.java:1242)
        at var.DatabaseLevelReport.doGet(Unknown Source)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


这看起来像一个已知问题,但我仍然无法解决:

See here
here

最佳答案

所以最终问题解决了。错误基本上是jfree对象无法启动。

jfree构造函数尝试进行一些静态初始化,但其中失败了。

即使是在类路径中,其原因仍是以下jar:
gnome-java-bridge.jar

只需在accessibility.properties文件中注释掉类名,就可以防止Java尝试加载该类。

这看起来像一个已知问题:
Reference1
Reference2

之后,一切工作都非常正常!

感谢你的帮助!非常感激。

09-27 17:31