问题描述
我想从jasper文件路径获取JasperReport。我的jasper文件路径是 C:/project/report/reportTemplate_20110420000035982.jasper
I want to get a JasperReport from a jasper file path. My jasper file path is C:/project/report/reportTemplate_20110420000035982.jasper
public static JasperReport getJasperReportByTemplateName(String templateFullName) throws JRException{
JasperReport jasperReport;
jasperReport = (JasperReport)JRLoader.loadObjectFromLocation(templateFullName);
return jasperReport;
}
此行发生异常:
jasperReport = (JasperReport)JRLoader.loadObjectFromLocation(templateFullName);
我试图找到原因,但看起来一切正常。我猜可能路径不是
在Windows中有效( C:/project/report/reportTemplate_20110420000035982.jasper
)
I tried to find the reason, but it looks like everything is ok. I guess may be the path is notvalid in Windows (C:/project/report/reportTemplate_20110420000035982.jasper
)
任何可以帮助我的人,非常感谢。我已粘贴下面的异常信息。谢谢。
Anyone who can help me, thanks a lot. I've pasted the exception info below. Thanks.
net.sf.jasperreports.engine.JRException: Could not load object from location : C:/project/report/reportTemplate_20110420000035982.jasper
at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:262)
at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:221)
at com.hp.proctool.reportmgt.customizer.IReportFactory.getJasperReportByTemplateName(IReportFactory.java:68)
at com.hp.proctool.reportmgt.service.ReportManager.getParametersByTemplateName(ReportManager.java:410)
at com.hp.proctool.reportmgt.service.ReportManager.getFieldJs(ReportManager.java:360)
at com.hp.proctool.reportmgt.service.ReportManager.generateReportDownloadForm(ReportManager.java:345)
at com.hp.proctool.reportmgt.service.ReportManager$$FastClassByCGLIB$$c444a9f1.invoke()
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
at com.hp.proctool.reportmgt.service.ReportManager$$EnhancerByCGLIB$$1ab1a55e.generateReportDownloadForm()
at com.hp.proctool.reportmgt.web.ReportController.generateDownloadForm(ReportController.java:148)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:421)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:136)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:326)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:313)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.hp.common.orm.RightFilter.doFilter(RightFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
推荐答案
在,看起来此行正在为您的文件返回 null
。
Looking at the source code of JRLoader
at http://jasperreports.sourcearchive.com/documentation/3.6.0plus-pdfsg/JRLoader_8java-source.html, it looks like this line is returning null
for your file.
File file = JRResourcesUtil.resolveFile(location, fileResolver);
这似乎暗示文件丢失或不是文件(即目录)。
which seems to suggest the file is either missing or not a file (i.e. a directory).
如果你打电话:
new File("C:/project/report/reportTemplate_20110420000035982.jasper").exists()
你得到真还是假?
您可以尝试调用 JRLoader#loadObject()
传入 FileInputStream
你自己创造的?
Could you try calling JRLoader#loadObject()
passing in a FileInputStream
that you create yourself?
这篇关于jasper无法从位置加载对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!