title: How to get jasper report to load from jar file?
body: <p>How do you get a compiled jasper report to load from within the jar file, instead of via a specific path on your hard drive?</p>
  
  <p>My report was working fine on my machine as I had set the path to the reports with:</p>
  
  <pre><code>jasperReport1 = (JasperReport) JRLoader.loadObjectFromFile("/Users/admin/Documents/HCCE/Semester 2/OOP/Projects2/TestApp/src/ie/test/OMACYTDReportFinalpg1.jasper");
  jasperReport2 =(JasperReport) JRLoader.loadObjectFromFile("/Users/admin/Documents/HCCE/Semester 2/OOP/Projects2/TestApp/src/ie/test/OMACYTDReportFinalpg2.jasper");
  </code></pre>
  
  <p>But the reports were not loading when working from the finished jar on a different computer. So I am trying to use Input stream and passing it to JasperFillManager but nothing is working - the InputStream is not finding the files. Have I the path wrong?</p>
  
  <pre><code>InputStream jasper1 = getClass().getResourceAsStream("src/ie/test/OMACYTDReportFinalpg1.jasper");
  InputStream jasper2 = getClass().getResourceAsStream("src/ie/test/OMACYTDReportFinalpg2.jasper");
  </code></pre>
  
  <p>My original working code:</p>
  
  <pre><code>private void yTDReportBtnActionPerformed(java.awt.event.ActionEvent evt) {                                             
      try
      {
          JasperReport jasperReport1 = null;
          JasperReport jasperReport2 = null;
          JasperPrint jasperPrint = null;
          JasperDesign jasperDesign = null;
          Map parameters = new HashMap();
          SimpleDateFormat formatter = new SimpleDateFormat("dd-mmm-yyyy");  
          String today = formatter.format(new java.util.Date());
  
          //load just the compiled jasper files, to save time
          //First merge the two jasper reports into one to get page1 and page 2 in same document
  
          jasperReport1 = (JasperReport) JRLoader.loadObjectFromFile("/Users/admin/Documents/HCCE/Semester 2/OOP/Projects2/TestApp/src/ie/test/OMACYTDReportFinalpg1.jasper");
          jasperReport2 =(JasperReport) JRLoader.loadObjectFromFile("/Users/admin/Documents/HCCE/Semester 2/OOP/Projects2/TestApp/src/ie/test/OMACYTDReportFinalpg2.jasper");
  
          JasperPrint jp1 = JasperFillManager.fillReport(jasperReport1, parameters,new JRBeanCollectionDataSource(ie.test.BeanFactory.getCalcs()));
          JasperPrint jp2 = JasperFillManager.fillReport(jasperReport2, parameters, new JRBeanCollectionDataSource(ie.test.BeanFactory.getCalcs()));
  
          List pages = jp2 .getPages();
          for (int j = 0; j &lt; pages.size(); j++) {
          JRPrintPage object = (JRPrintPage)pages.get(j);
          jp1.addPage(object);
          jp1.setName(unitNameLbl.getText() + " - Financial Year To Date - " + today );
  
  }
          JasperViewer.viewReport(jp1, false);
  
      }
      catch(Exception ex)
      {
          System.out.println("EXCEPTION: "+ex.getMessage() + ex);
      }
  }                        
  </code></pre>
  
  <p>And now the changed code that is not working:</p>
  
  <pre><code>private void yTDReportBtnActionPerformed(java.awt.event.ActionEvent evt) {                                             
      try
      {
          JasperReport jasperReport1 = null;
          JasperReport jasperReport2 = null;
          JasperPrint jasperPrint = null;
          JasperDesign jasperDesign = null;
          Map parameters = new HashMap();
          SimpleDateFormat formatter = new SimpleDateFormat("dd-mmm-yyyy");  
          String today = formatter.format(new java.util.Date()); 
  
          //load just the compiled jasper files, to save time
          //First merge the two jasper reports into one to get page1 and page 2 in same document
          InputStream jasper1 = getClass().getResourceAsStream("src/ie/test/OMACYTDReportFinalpg1.jasper");
          InputStream jasper2 = getClass().getResourceAsStream("src/ie/test/OMACYTDReportFinalpg2.jasper");
  
  
          JasperPrint jp1 = JasperFillManager.fillReport(jasper1, parameters,new JRBeanCollectionDataSource(ie.test.BeanFactory.getCalcs()));
          JasperPrint jp2 = JasperFillManager.fillReport(jasper2, parameters, new JRBeanCollectionDataSource(ie.test.BeanFactory.getCalcs()));
  
          List pages = jp2 .getPages();
          for (int j = 0; j &lt; pages.size(); j++) {
          JRPrintPage object = (JRPrintPage)pages.get(j);
          jp1.addPage(object);
          jp1.setName(unitNameLbl.getText() + " - Financial Year To Date - " + today );
  
  }
          JasperViewer.viewReport(jp1, false);
  
  
      }
      catch(Exception ex)
      {
          System.out.println("EXCEPTION: "+ex.getMessage() + ex);
      }
  }
  </code></pre>
  
  <p>Any help greatly appreciated!    </p>
  
  <p>Ok update: I got the InputStreams to work by creating a new package called "reports" and using</p>
  
  <pre><code>InputStream jasper1 = getClass().getResourceAsStream("/reports/OMACYTDReportFinalpg1.jasper");
  InputStream jasper2 = getClass().getResourceAsStream("/reports/OMACYTDReportFinalpg2.jasper");     
  </code></pre>
  
  <p>And this works fine in Netbeans BUT it still won't load the files when I compile to jar!!?</p>
  
  <p>Any ideas what I'm doing wrong?                      </p>