title: How to get jasperreport file (.JRXML) exact location to load to the system?
body: <p>I trying to load jasper report (.jrxml) that i created, i named the report "JREmp1.xml". but i got this error </p>
  
  <blockquote>
    <p>"HTTP Status 500 - Request processing failed; nested exception is
    net.sf.jasperreports.engine.JRException:
    java.io.FileNotFoundException:
    D:\printpdf.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\JasperExample\jasper\JREmp1.jrxml
    (The system cannot find the path specified)"</p>
  </blockquote>
  
  <p>how to got the exact location? here is my JREmp1.xml file location :
  <a href="https://i.stack.imgur.com/6XpWf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6XpWf.png" alt="enter image description here"></a></p>
  
  <p>and here is code in my controller class :</p>
  
  <pre><code>@RequestMapping(value = "/generateReport", method = RequestMethod.POST)
  public String generateReport(
          @Valid @ModelAttribute("jasperInputForm") JasperInputForm jasperInputForm,
          BindingResult result, Model model, HttpServletRequest request,
          HttpServletResponse response) throws JRException, IOException,
          NamingException {
  
      if (result.hasErrors()) {
          System.out.println("validation error occured in jasper input form");
          return "loadJasper";
  
      }
  
      String reportFileName = "JREmp1";
      JasperReportDAO jrdao = new JasperReportDAO();
  
      Connection conn = null;
  
      try {
          conn = jrdao.getConnection();
  
          String rptFormat = jasperInputForm.getRptFmt();
          String noy = jasperInputForm.getNoofYears();
  
          System.out.println("rpt format " + rptFormat);
          System.out.println("no of years " + noy);
  
          HashMap&lt;String, Object&gt; hmParams = new HashMap&lt;String, Object&gt;();
  
          hmParams.put("noy", new Integer(noy));
  
          hmParams.put("Title", "Employees working more than " + noy
                  + " Years");
  
          JasperReport jasperReport = jrdao.getCompiledFile(reportFileName,
                  request);
  
          if (rptFormat.equalsIgnoreCase("html")) {
              JasperPrint jasperPrint = JasperFillManager.fillReport(
                      jasperReport, hmParams, conn);
              jrdao.generateReportHtml(jasperPrint, request, response); // For
              // HTML
              // report
          }
          else if (rptFormat.equalsIgnoreCase("pdf")) {
              jrdao.generateReportPDF(response, hmParams, jasperReport, conn); // For
              // PDF
              // report
          }
      } catch (SQLException sqlExp) {
          System.out.println("Exception::" + sqlExp.toString());
      } finally {
          if (conn != null) {
              try {
                  conn.close();
                  conn = null;
              } catch (SQLException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
      }
      return null;
  }
  </code></pre>
  
  <p>Here is the code in my <code>JasperReportDAO</code> class :</p>
  
  <pre><code>public JasperReport getCompiledFile(String fileName, HttpServletRequest request) throws JRException {
      System.out.println("path " + request.getSession().getServletContext().getRealPath("/jasper/" + fileName + ".jasper"));
      File reportFile = new File( request.getSession().getServletContext().getRealPath("/jasper/" + fileName + ".jasper"));
      // If compiled file is not found, then compile XML template
      if (!reportFile.exists()) {
          JasperCompileManager.compileReportToFile(request.getSession().getServletContext().getRealPath("/jasper/" + fileName + ".jrxml"),request.getSession().getServletContext().getRealPath("/jasper/" + fileName + ".jasper"));
      }
      JasperReport jasperReport = (JasperReport) JRLoader.loadObjectFromFile(reportFile.getPath());
      return jasperReport;
  }
  
  
  public void generateReportHtml( JasperPrint jasperPrint, HttpServletRequest req, HttpServletResponse resp) throws IOException, JRException {
      HtmlExporter exporter=new HtmlExporter();
      List&lt;JasperPrint&gt; jasperPrintList = new ArrayList&lt;JasperPrint&gt;();
      jasperPrintList.add(jasperPrint);
      exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));
      exporter.setExporterOutput( new SimpleHtmlExporterOutput(resp.getWriter()));
      SimpleHtmlReportConfiguration configuration =new SimpleHtmlReportConfiguration();
      exporter.setConfiguration(configuration);
      exporter.exportReport();
  
  }
  
  
  public void generateReportPDF (HttpServletResponse resp, Map parameters, JasperReport jasperReport, Connection conn)throws JRException, NamingException, SQLException, IOException {
      byte[] bytes = null;
      bytes = JasperRunManager.runReportToPdf(jasperReport,parameters,conn);
      resp.reset();
      resp.resetBuffer();
      resp.setContentType("application/pdf");
      resp.setContentLength(bytes.length);
      ServletOutputStream ouputStream = resp.getOutputStream();
      ouputStream.write(bytes, 0, bytes.length);
      ouputStream.flush();
      ouputStream.close();
  }
  </code></pre>
  
  <p>and here is my <code>JasperInputForm</code> class :</p>
  
  <pre><code>public class JasperInputForm {
  
      @NotEmpty
      private String noofYears;
      private String rptFmt="Html";
  
      public String getRptFmt() {
          return rptFmt;
      }
  
      public void setRptFmt(String rptFmt) {
          this.rptFmt = rptFmt;
      }
  
      public String getNoofYears() {
          return noofYears;
      }
  
      public void setNoofYears(String noofYears) {
          this.noofYears = noofYears;
      }
  
  }
  </code></pre>
  
  <p>how to get my <code>JREmp1.jrxml</code> file location properly? I develop this report for Spring MVC application</p>
  
  <p>UPDATE :
  Here is my complete function code after i update with @Wilson answer (i go with second option that @Wilson said) :
  this function is inside JasperReportDAO :</p>
  
  <pre><code>public JasperReport getCompiledFile(String fileName, HttpServletRequest request) throws JRException, MalformedURLException, URISyntaxException {
      System.out.println("path " + request.getSession().getServletContext().getRealPath("/jasper/" + fileName + ".jasper"));
      //File reportFile = new File( request.getSession().getServletContext().getRealPath("/jasper/" + fileName + ".jasper"));
      URL resourceUrl = request.getSession().getServletContext().getResource("/WEB-INF/jasper/" + fileName + ".jrxml");
      File reportFile = new File(resourceUrl.toURI());
  
      // If compiled file is not found, then compile XML template
      if (!reportFile.exists()) {
                 JasperCompileManager.compileReportToFile(request.getSession().getServletContext().getRealPath("/jasper/" + fileName + ".jrxml"),request.getSession().getServletContext().getRealPath("/jasper/" + fileName + ".jasper"));
          }
          JasperReport jasperReport = (JasperReport) JRLoader.loadObjectFromFile(reportFile.getPath());
         return jasperReport;
  }
  </code></pre>
  
  <p>and i got this error </p>
  
  <blockquote>
    <p>"HTTP Status 500 - Request processing failed; nested exception is
    java.lang.IllegalArgumentException: URI scheme is not "file""</p>
  </blockquote>
  
  <p>How to solve this?</p>