FileNotFoundException while I am using jasper report

后端 未结 4 1912
说谎
说谎 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:34

    OK.Guys this worked for me

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

    After this copy or cut the jasperfile eg.(your_reportname.jasper and your_reportname.jrxml) and go to the File directory of your project(easy to find in netbeans) and paste them in the build.xml folder of the project .Making sure you have imported the necesasry class jars and run.. im using the jasperreport 3.7.4 plugin for netbeans in my netbeans ide

    0 讨论(0)
  • 2021-01-06 19:34

    In my case I had an image url parameter and had to explicitly set the attribute isForPropmting to false like this:

    <parameter name="LOGO_URL" class="java.lang.String" isForPrompting="false">
            <defaultValueExpression><![CDATA[]]></defaultValueExpression>
        </parameter>
    
    0 讨论(0)
  • 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");
      
    0 讨论(0)
  • 2021-01-06 19:46

    I think your .jasper file is not in your context path of application (Atleast the application is not finding it).

    Are you sure the /report folder is in build path?? If not, add it to build path.

    Otherwise try to use something like this JasperReport report = JasperCompileManager.compileReport("classpath:src/com/ztscorp/lms/reports/HibernateQueryDemoReport.jasper");

    try this,

    change

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

    to

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

    Hope it helps,

    -Anuj

    0 讨论(0)
提交回复
热议问题