我正在使用jasper报告时FileNotFoundException

时间:2012-01-06 13:18:30

标签: jasper-reports

我正在尝试在Liferay portlet中创建Jasper报告,但我收到了以下错误:

   Caused by: net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException:    src\com\ztscorp\lms\reports\HibernateQueryDemoReport.jasper (The system cannot find the path specified)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:176)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156)
        at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:143)
        at com.ztscorp.lms.portlet.SurveyReportController.processSearchSurvey(SurveyReportController.java:86)
        ... 175 more
Caused by: java.io.FileNotFoundException: src\com\ztscorp\lms\reports\HibernateQueryDemoReport.jasper (The system cannot find the path specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:171)
        ... 178 more
13:08:01,916 ERROR [[SurveyReportAdministration]] Servlet.service() for servlet SurveyReportAdministration threw exception
java.io.FileNotFoundException: src\com\ztscorp\lms\reports\HibernateQueryDemoReport.jasper (The system cannot find the path specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:171)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156)
        at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:143)
        at com.ztscorp.lms.portlet.SurveyReportController.processSearchSurvey(SurveyReportController.java:86)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at javax.portlet.GenericPortlet.processAction(GenericPortlet.java:169)
        at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
        at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
        at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:92)
        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.ztscorp.lms.utils.AuthenticateFilter.doFilter(AuthenticateFilter.java:99)
        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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:543)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:480)
        at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:638)
        at com.liferay.portlet.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:687)
        at com.liferay.portlet.InvokerPortletImpl.processAction(InvokerPortletImpl.java:360)
        at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:784)
        at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:582)
        at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:232)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
        at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:153)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:508)
        at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:485)
        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.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:309)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:121)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:182)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:254)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:444)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
        at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:134)
        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.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:261)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:110)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:182)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:222)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

这是我的代码:

Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/lms?user=root&password=admin");

JasperReport report = JasperCompileManager.compileReport("src/com/ztscorp/lms/reports/HibernateQueryDemoReport.jasper");
JasperPrint print = JasperFillManager.fillReport(report, new HashMap(), connection);
JasperExportManager.exportReportToPdfFile(print, "reports/myjasperfile.pdf");

请帮帮我。

4 个答案:

答案 0 :(得分:1)

为了帮助未来的用户:

我看到了这些问题

  1. OP正在尝试编译.jasper,这些.jasper文件已经编译,命令JasperCompileManager.compileReport应该用于将.jrxml编译为{ {1}}。有关jasper报告文件类型的详细信息,请参阅What is the difference between JasperReport formats?
  2. 如果您的软件包/发行版(src)中有.jasper ,那么加载报表的正确方法是使用类加载器(因此src会更改) bin)。

    .jasper

    如果分发 之外,您可以简单地将InputStream jasperStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("com/ztscorp/lms/reports/HibernateQueryDemoReport.jasper"); JasperReport report = (JasperReport) JRLoader.loadObject(jasperStream); 与相对路径或绝对路径一起使用

    File

答案 1 :(得分:1)

OK.Guys这对我有用

  ***con=DBConnection.getConnection();
  JasperPrint  jp = JasperManager.fillReport(<reportname>.jasper",null,con);
        JasperViewer.viewReport(jp, false);***

在复制或剪切jasperfile之后,例如。(your_reportname.jasper和your_reportname.jrxml)并转到项目的File目录(很容易在netbeans中找到)并将它们粘贴到项目的build.xml文件夹中。确保你已经导入了necesasry类jar并运行..我使用jbeperreport 3.7.4插件为我的netbeans ide中的netbeans

答案 2 :(得分:0)

我认为您的.jasper文件不在您的应用程序的上下文路径中(Atleast应用程序找不到它)。

你确定/ report文件夹在构建路径中吗? 如果没有,请将其添加到构建路径。

否则尝试使用类似JasperReport report = JasperCompileManager.compileReport("classpath:src/com/ztscorp/lms/reports/HibernateQueryDemoReport.jasper");

的内容

试试这个,

变化

JasperReport report = JasperCompileManager.compileReport("src/com/ztscorp/lms/reports/HibernateQueryDemoReport.jrxml");

JasperReport report = JasperCompileManager.compileReport(new File("").getAbsolutePath()+"src/com/ztscorp/lms/reports/HibernateQueryDemoReport.jrxml");

希望它有所帮助,

-Anuj

答案 3 :(得分:0)

在我的情况下,我有一个图片网址参数,并且必须明确将属性 isForPropmting 设置为false,如下所示:

<parameter name="LOGO_URL" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA[]]></defaultValueExpression>
    </parameter>