How to call a report created with iReport

Asked

Viewed 2,895 times

1

I am in the following situation: I received several reports created by another developer, who used iReport. He sent me the files .jasper and .jrxml.

I have installed Eclipse Kepler with Jaspersoft plugin.

How can I fire the reports from a JFrame, where I already have all the buttons to make these calls? I use Mysql as BD.

Could someone give a help or an example?

1 answer

4

Augusto,

You can do it this way:

        Map parametros = new HashMap();
        String relatorio = "caminhodorelatorio\\arquivo.jasper";
        JasperPrint jasperPrint = JasperFillManager.fillReport(relatorio, parametros);            
        JasperViewer view = new JasperViewer(jasperPrint, false);
        view.setVisible(true);

It is necessary to place the following Imports in your class:

import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

Edit: the variable "parameters" is a parameter of type Map, which must be passed in the fillReport method.

inserir a descrição da imagem aqui

In this variable you can add values to be used in the report, for example: a report title

parametros.put("ReportTitle", "PDF JasperReport");
  • Thanks for the reply, but in the line Jasperprint jasperPrint = Jasperfillmanager.fillReport(report, parameters) what would be the parameters to be passed? Those who sent me the reports said that there is no need to pass any parameters, as they are informed when any of the reports are called. It is possible to fire without passing parameters?

  • I edited the original answer.

  • Ok, but I’m not finding these . jars to impose. Where are these libraries when the plugin is installed in Eclipse?

  • 1

    I downloaded Jasper’s jar and made the correct Iimports. I created a test class and is generating the following error: Exception in thread "AWT-Eventqueue-0" java.lang.Noclassdeffounderror: org/apache/Commons/logging/Logfactory // What might be happening? Thanks for the help !!!

  • Noclassdeffounderror is a very common mistake. Take a look at the explanation about it: http://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java But in your case, it’s probably the lack of these jars in your classpath! has all the explanation for this problem: http://javafree.uol.com.br/topic-14396-CLASSPATH-E-PATH-PARA-O-IREPORT-E-JASPERREPORT.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.