Error: net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException:

0

Hello, I am new to Jasper Reports and I am not sure where to store my ".jrxml" and ".jasper" files.

In my project, I have stored all my files in the src file folder, including the ".jrxml" and ".jasper" files but i receive an exception.

Can someone please tell/explain what i could be doing wrong and a solution for it, also where to store my files.

thank you

My code snippet is as follows :

 

Code:
 try {
             Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection con =DriverManager.getConnection("jdbc:sqlserver://localhost;" +
                    "instanceName=SQLEXPRESS2008;databaseName=OMA2008_DB;", "sa", "admin2008");
             JasperReport jasperReport =
                        JasperCompileManager.compileReport("newReport.jrxml");
 
             JasperPrint print = JasperFillManager.fillReport(jasperReport, parameter, con);
 
             JRViewer viewer = new JRViewer(print);
            Container c = getContentPane();
            c.setLayout(new BorderLayout());
            c.add(viewer);
 
         } catch (ClassNotFoundException cnfe) {
            cnfe.printStackTrace();
            System.out.println("Error: " + cnfe.toString());
         } catch(SQLException sqle) {
             System.out.println("Error: " + sqle.toString());
             sqle.printStackTrace();
         } catch(JRException jre) {
             System.out.println("Error: " + jre.toString());
            jre.printStackTrace();
         } catch (JRRuntimeException e) {
             System.out.println("Error: " + e.toString());
         }</td></tr></tbody></table>
Zweli's picture
4
Joined: Mar 25 2011 - 1:05am
Last seen: 1 year 4 months ago

2 Answers:

0

First, it's hard to find a situation where makes sense to compile a report (jrxml) file in your running application, and it seems your application have no need for this. You should keep the 'jrxml' files as part of your project, but only include the 'jasper' into the classpath, as it is already compiled and ready to use.

As an example, in my project I keep the 'jasper' files into a 'resources' source folder, which will be included in my packaged application, so it can be easily loaded. The snippet below should make it clearer.

So, put the 'jasper' files in your application classpath, and leave the source files (jrxml) out, as they will be useless for your running application.

Code:
String reportPath = "/com/company/reports/myreport.jasper";
InputStream reportStream = MyReportService.class.getResourceAsStream(reportPath);
if (reportStream == null) {
    throw new SomeException("Report not found!");
}
 
JasperPrint print = JasperFillManager.fillReport(reportStream, parameters, dataSoruce);
 
//...


Post Edited by mdrg at 03/25/2011 16:40
mdrg's picture
45
Joined: Feb 18 2011 - 11:14am
Last seen: 9 years 1 week ago
-1

hi...i have a problem that is where to store jrxmls& jaspers in our running application...from the above discussed topics u asked to save only jasper...so i created a package in src and kept .jasper  files in it...but i got file not found exception.

should we change default expression in jrxmls also?

if we have to change how and where we have to change it?

initially i stored my jrxmls&.jasper in jasperreports folder in c drive.

please do help...its really important and urgent....

thanks in advance...

Code:
<defaultValueExpression><![CDATA["C:\\\\JasperReports\\\\"]]></defaultValueExpression></td></tr></tbody></table>
jasti's picture
1
Joined: Jun 10 2012 - 9:19pm
Last seen: 5 years 5 months ago
Feedback