FileNotFoundException while I am using jasper report

后端 未结 4 1951
说谎
说谎 2021-01-06 19:10

I am trying to create Jasper Report in Liferay portlet but I am getting below error:

   Caused by: net.sf.jasperreports.engine.JRException: java.io.FileNotF         


        
4条回答
  •  自闭症患者
    2021-01-06 19:36

    To help future users:

    I see these problems

    1. OP is trying to compile .jasper, these .jasper files are already compiled the command JasperCompileManager.compileReport should be used to compile .jrxml to .jasper. For more information of jasper report file types see What is the difference between JasperReport formats?
    2. If you have you .jasper inside of your package/distribution (src), the correct way to load the report would be using a class loader (hence src will change to bin).

      InputStream jasperStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("com/ztscorp/lms/reports/HibernateQueryDemoReport.jasper");
      JasperReport report = (JasperReport) JRLoader.loadObject(jasperStream);
      

      If it outside of the distribution you can simple use File with the relative or absolute path

      JasperReport report = (JasperReport) JRLoader.loadObject(new File("jasperFolder/HibernateQueryDemoReport.jasper");
      

提交回复
热议问题