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.
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?
– Augusto Cesar Nunes
I edited the original answer.
– Alexandre Strevenski
Ok, but I’m not finding these . jars to impose. Where are these libraries when the plugin is installed in Eclipse?
– Augusto Cesar Nunes
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 !!!
– Augusto Cesar Nunes
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
– Alexandre Strevenski