Good afternoon guys, I'm having a problem I'm not able to get the subrelator path to the main report. I'll go the code I've done so far, please help me, I do not know what I'm doing wrong. Please be specific as I have no experience with JasperReports. I'm using Jasper Studio and Jasper in version 5.0.1
Error:
log4j:WARN No appenders could be found for logger (net.sf.jasperreports.engine.xml.JRXmlDigesterFactory).
log4j:WARN Please initialize the log4j system properly.
net.sf.jasperreports.engine.JRException: Resource not found at : debitos.jasper
at net.sf.jasperreports.repo.RepositoryUtil.getResourceFromLocation(RepositoryUtil.java:255)
at net.sf.jasperreports.repo.RepositoryUtil.getReport(RepositoryUtil.java:208)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateReport(JRFillSubreport.java:328)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:361)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:286)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:459)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2044)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:778)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:288)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:151)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:841)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:88)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:969)
at br.com.loov.mycash.relatorio.GeradorRelatorio.geraPdf(GeradorRelatorio.java:35)
at br.com.loov.mycash.controller.RelatorioMensalController.doGet(RelatorioMensalController.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at br.com.loov.mycash.filtro.LoginFiltro.doFilter(LoginFiltro.java:47)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:412)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:754)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1385)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Class Generating or Reporting:
package br.com.loov.mycash.relatorio;
import java.io.OutputStream;
import java.util.Map;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.export.JRPdfExporter;
public class GeradorRelatorio {
private JRBeanCollectionDataSource jrBeanCollectionDataSource;
public GeradorRelatorio() {
}
public GeradorRelatorio(JRBeanCollectionDataSource jrBeanCollectionDataSource) {
this.jrBeanCollectionDataSource = jrBeanCollectionDataSource;
}
public void geraPdf(String jrxml,
Map<String, Object> parametros, OutputStream saida) {
try {
// compila jrxml em memoria
JasperReport jasper = JasperCompileManager.compileReport(jrxml);
// preenche relatorio
JasperPrint print = JasperFillManager.fillReport(jasper, parametros, this.jrBeanCollectionDataSource);
// exporta para pdf
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, saida);
exporter.exportReport();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Report Controller:
package br.com.loov.mycash.controller;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jdt.internal.compiler.batch.Main;
import br.com.loov.mycash.dao.ContaDAO;
import br.com.loov.mycash.model.Conta;
import br.com.loov.mycash.relatorio.GeradorRelatorio;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.util.FileResolver;
@WebServlet("/RelatorioMensalController")
public class RelatorioMensalController extends HttpServlet {
private static final long serialVersionUID = 1L;
private ContaDAO dao = new ContaDAO();
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int idUsuario = Integer.parseInt(request.getParameter("idUsuario"));
System.out.println(idUsuario);
// acha jrxml dentro da aplicação
ServletContext contexto = request.getServletContext();
String jrxml = contexto.getRealPath("relatorio/relatorioMensal.jrxml");
String jasper = contexto.getRealPath("relatorio/");
// prepara parâmetros
Map<String, Object> parametros = new HashMap<>();
parametros.put("SUBREPORT_DIR",jasper);
// gera relatório
List<Conta> listaConta = dao.listar(idUsuario);
GeradorRelatorio gerador = new GeradorRelatorio(new JRBeanCollectionDataSource(listaConta));
gerador.geraPdf(jrxml, parametros, response.getOutputStream());
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
git link where is the report code: Link