Error generating a document in Jasper Report

0

I'm doing a registration form in Japer Report, when I call them from java and I run the generation of the document I get the following error:

java.io.FileNotFoundException: \WebCampeonatoDeportivo\src\net\cibertec\campeonatoDeportivo\documentos\ficha_inscripcion.jasper (El sistema no puede encontrar la ruta especificada)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:146)
    at java.io.FileInputStream.<init>(FileInputStream.java:101)
    at net.cibertec.campeonatoDeportivo.action.EquipoAction.GenerarFichaInscripcion(EquipoAction.java:317)
    at net.cibertec.campeonatoDeportivo.action.EquipoAction.GrabarEquipo(EquipoAction.java:296)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:279)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:78)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Errornull

This is the code that generated the document:

@SuppressWarnings({ "static-access", "deprecation" })
public void GenerarFichaInscripcion() throws Exception{
    SqlDBConexion cn = new SqlDBConexion();
    JasperReport jr = null;
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    ServletContext context = (ServletContext) externalContext.getContext();
    jr = (JasperReport) JRLoader.loadObjectFromFile(context.getRealPath("/WEB-INF/docs/ficha_inscripcion.jasper"));
    try {
        JasperPrint jasperPrint;
        jasperPrint = JasperFillManager.fillReport(jr, null,cn.getConexion());
        JasperViewer jv=new JasperViewer(jasperPrint,false);
        jv.show();
        System.out.println("Visualizando el reporte en Desktop");
        System.out.println("Agregado exitosamente");
    } 
    catch (Exception e) {
        System.out.println("Error"+e.getMessage());
        //e.printStackTrace();
    }
}

It is an application made in Java Web with primefaces and Jasper Report.

    
asked by B.Torres 09.10.2017 в 21:42
source

1 answer

1

The problem indicates that you can not find your file ficha_inscripcion.jasper

If the file is inside your web project you have to do the following:

ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
            ServletContext context = (ServletContext) externalContext.getContext();
            JasperReport desing = (JasperReport) JRLoader.loadObjectFromFile(context.getRealPath("/WEB-INF/docs/nombreReporte.jasper"));

In this example I have my file inside the folder WEB-INF there is a folder called docs and inside this folder is my file nameReport.jasper

Usually ExternalContext , it offers access to specific artifacts of Servlets or Portlets that JSF currently uses " under the covers. " For example, when running in a Servlet container, the HTTP servlet request, the HTTP servlet response, the HTTP session and the Servlet context and inherently all its artifacts as well.

Here you can find a example.

    
answered by 09.10.2017 в 22:25