2014-01-07 80 views
-1

以下是在main()方法中正常工作的代碼。編譯並給出了.jasper文件,然後作爲一個輸出I/O文件寫入代碼錯誤

package com; 

import net.sf.jasperreports.engine.JRException; 
import net.sf.jasperreports.engine.JasperCompileManager; 

public class JasperCompile { 
    public static void main(String args[]) throws JRException { 
     JasperCompileManager.compileReportToFile("C:\\temp.jrxml", "C:\\temp.jasper"); 
    } 
} 

但是,當我嵌入以下從main()方法行servlet的doGet方法,那麼它不工作

JasperCompileManager.compileReportToFile("C:\\temp.jrxml", "C:\\temp.jasper"); 

以下是堆棧跟蹤。

Jan 7, 2014 4:19:21 PM org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Servlet.service() for servlet [JasperReportsBrowserDemoServlet] in context with path [/PDFReports] threw exception [Servlet execution threw an exception] with root cause 
java.lang.NoSuchMethodError: org.apache.commons.digester.Digester.addSetProperties(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/StringV 
at net.sf.jasperreports.components.ComponentsXmlHandler.addListRules(ComponentsXmlHandler.java:117) 
at net.sf.jasperreports.components.ComponentsXmlHandler.configureDigester(ComponentsXmlHandler.java:104) 
at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.addComponentRules(JRXmlDigesterFactory.java:514) 
at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.configureDigester(JRXmlDigesterFactory.java:493) 
at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createDigester(JRXmlDigesterFactory.java:1324) 
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:207) 
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:172) 
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156) 
at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:108) 
at com.JasperReportsBrowserDemoServlet.createJRXML(JasperReportsBrowserDemoServlet.java:136) 
at com.JasperReportsBrowserDemoServlet.doGet(JasperReportsBrowserDemoServlet.java:47) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) 
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) 
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) 
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) 
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
at java.lang.Thread.run(Thread.java:619) 
4:23 PM 

當我們在main()方法和服務器端編寫代碼時,它會產生什麼差別?

+0

JasperReport的版本是什麼? – esmoreno

+0

如果JasperReport的版本不正確,那麼爲什麼在main()方法中運行時會得到輸出。這兩個程序都使用了相同的jar文件。 – AmitG

回答

2

您的Apache Commons Digester版本不正確。查看JasperReport的所有依賴關係。

+0

如果Apache Commons Digester不正確,那麼爲什麼在main()方法中運行時會得到輸出。這兩個程序都使用了相同的jar文件。 – AmitG

+0

如果可能,類路徑中出現錯誤(重複的jar或類似問題) – esmoreno

+0

當您作爲servlet調用時,您的服務器正在使用其他Apache Commons Digester jar。要進行快速測試,請將您的庫放入Web項目的lib文件夾中,然後再次測試。 – esmoreno