Quais formatos do relatório devo distribuir? Apenas os .jasper? Eles devem ser distribuídos no .jar ou separadamente?
Os arquivos .jasper… ou seja, os arquivos compilados…
[quote=lbvitoriano]Olha aparentemente está td certo na chamada dele e tal…mas vc disse q não dá erro nenhum…isso q é esquisito…
Enfim, tente mudar isso…
Ao invés disso…
URL arquivo = getClass().getResource("FolhaRosto.jasper");
Faça assim…
URL arquivo = getClass().getResource("/caminhoDoArquivoJasper/FolhaRosto.jasper");
[/quote]
Quando você pede que faça essa alteração, você sugere que coloque o caminho a partir da raiz (c:/…). E se os .jasper estiverem dentro do .jar distribuido? Indica esse caminho assim mesmo?
Primeiro crie um Folder dentro do seu projeto chamado: lib
Coloque os seguintes jar’s dentro do folder lib:
commons-collections-2.1.jar
commons-javaflow-20060411.jar
commons-logging-api-1.0.2.jar
iReport.jar
jasperreports-3.0.0.jar
mysql-connector-java-3.1.11-bin.jar //Pode ser outra versão mais recente.
Em propriedades de seu projeto entre em: Java Build Path> Add JARs…> adicione todos arquivos .jar descrito acima da pasta lib.
Coloque o seu arquivo de relatório .jasper dentro da pasta projeto.
Depois é só geral o jar utilizando o FatJar Exporter.
Se seu .jar do projeto tiver em desktop copie o relatorio.jasper tambem em desktop.
Se precisar dos jar’s é só pedir.
[quote=lbvitoriano]Não q eu saiba, mesmo pq vc ta usando ele na outra máquina e funciona…
Vc colocou um try catch() na chamada dessa sua tela do menu? E nada de erros, ou algo do tipo?[/quote]
Como postei anteriormente, as telas já estão funcionando normalmente, após eu transferir as bibliotecas para a pasta onde está instalado o sistema. Tudo funciona normalmente menos os relatórios que simplesmente não aparecem ou não são construídos, não sei bem ao certo. Alguém que tenha desenvolvido relatório jasperreports com IReports no NetBeans tem alguma dica? Meu problema acredito que seja na compilação/distribuição dos relatórios.
[quote=murilomenegasso]Primeiro crie um Folder dentro do seu projeto chamado: lib
Coloque os seguintes jar’s dentro do folder lib:
commons-collections-2.1.jar
commons-javaflow-20060411.jar
commons-logging-api-1.0.2.jar
iReport.jar
jasperreports-3.0.0.jar
mysql-connector-java-3.1.11-bin.jar //Pode ser outra versão mais recente.
Em propriedades de seu projeto entre em: Java Build Path> Add JARs…> adicione todos arquivos .jar descrito acima da pasta lib.
Coloque o seu arquivo de relatório .jasper dentro da pasta projeto.
Depois é só geral o jar utilizando o FatJar Exporter.
Se seu .jar do projeto tiver em desktop copie o relatorio.jasper tambem em desktop.
Se precisar dos jar’s é só pedir.
[/quote]
Murilo, vc utiliza NetBeans? Dá uma clareada neste roteiro que vc postou por favor.
Então eu utilizo Eclipse, mas é que no começo tive o mesmo problema, e foi assim que resolvi.
Att. Murilo.
To com um problema assim
meu projeto é Eclipse
e eu testando la funciona certin
dai trouxe para o netbeans para fazer o meu .jar
da o seguinte erroo
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at net.sf.jasperreports.engine.fill.JRBaseFiller.<clinit>(JRBaseFiller.java:96)
at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:147)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:57)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:402)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:234)
at dialogo.ImprimeRecibo.gerarEmpresa(ImprimeRecibo.java:573)
at dialogo.ImprimeRecibo$11.actionPerformed(ImprimeRecibo.java:438)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6041)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5806)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4413)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2440)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
... 32 more
oq ta acontecendo??
Vou postar as classes com algumas alterações para ver se alguém da mais alguma sugestão: HELP…
[code]/*
- TelaFolhaRosto.java
- Created on 26 de Outubro de 2009, 16:02
*/
import java.awt.Color;
import javax.swing.JOptionPane;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
*/
public class TelaFolhaRosto extends javax.swing.JFrame {
Color cinzaClaro = new Color(232,232,232);
public String varIdNrAI;
public String varIdNrTal;
/** Creates new form TelaFolhaRosto */
public TelaFolhaRosto() {
initComponents();
inibeCampos();
}
private void inibeCampos(){
txtAutuado.setEnabled(false);
txtAutuado.setBackground(cinzaClaro);
cmdImprimir.setEnabled(false);
cmdLimpar.setEnabled(false);
}
private void liberaCampos(){
txtAutuado.setEnabled(true);
txtAutuado.setBackground(Color.white);
cmdImprimir.setEnabled(true);
cmdLimpar.setEnabled(true);
}
private void LimpaCampos(){
txtNrAI.setValue(null);
txtNrTal.setValue(null);
txtAutuado.setText("");
}
private void pesquisaAI(){
try
{
String sql = "SELECT NRAI, NRTALAO, AUTUADO FROM TABAIS INNER JOIN TABAUTUADOS USING (IDAUTUADO) " +
"WHERE NRAI = '" + txtNrAI.getText() + "'AND NRTALAO = '" + txtNrTal.getText() + "'";
BD.setResultSet(sql);
if (BD.rs.first())
{
liberaCampos();
txtAutuado.setText(BD.rs.getString("AUTUADO"));
varIdNrAI = BD.rs.getString("NRAI");
varIdNrTal = BD.rs.getString("NRTALAO");
cmdImprimir.requestFocus();
}
else
{
JOptionPane.showMessageDialog(null,"Nº de Auto de Infração Não Cadastrado. Verifique!");
LimpaCampos();
txtNrAI.requestFocus();
}
}
catch(Exception erro)
{
JOptionPane.showMessageDialog(null,"Erro:"+erro.getMessage());
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
txtNrAI = new javax.swing.JFormattedTextField();
jLabel2 = new javax.swing.JLabel();
txtNrTal = new javax.swing.JFormattedTextField();
txtAutuado = new CamposMaiusculas();
jLabel3 = new javax.swing.JLabel();
cmdImprimir = new javax.swing.JButton();
cmdLimpar = new javax.swing.JButton();
cmdSair = new javax.swing.JButton();
setTitle("Impressão de Folha de Rosto");
setResizable(false);
jPanel1.setBackground(java.awt.Color.white);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados Auto de Infração", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 14))); // NOI18N
jLabel1.setFont(new java.awt.Font("Arial", 0, 14));
jLabel1.setText("Nº do AI"); // NOI18N
txtNrAI.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
try {
txtNrAI.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("#######")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
txtNrAI.setFont(new java.awt.Font("Arial", 0, 14));
txtNrAI.setName("txtNrAI"); // NOI18N
txtNrAI.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtNrAIActionPerformed(evt);
}
});
jLabel2.setFont(new java.awt.Font("Arial", 0, 14));
jLabel2.setText("Nº do Talão"); // NOI18N
txtNrTal.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
try {
txtNrTal.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("#####")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
txtNrTal.setFont(new java.awt.Font("Arial", 0, 14));
txtNrTal.setName("txtNrTal"); // NOI18N
txtNrTal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtNrTalActionPerformed(evt);
}
});
txtAutuado.setFont(new java.awt.Font("Arial", 0, 14));
txtAutuado.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
txtAutuado.setName("txtAutuado"); // NOI18N
jLabel3.setFont(new java.awt.Font("Arial", 0, 14));
jLabel3.setText("Nome");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(23, 23, 23)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtNrAI, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(82, 82, 82)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtNrTal, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(151, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtAutuado, javax.swing.GroupLayout.PREFERRED_SIZE, 478, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(69, 69, 69))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(27, 27, 27)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txtNrAI, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(txtNrTal, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txtAutuado, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
cmdImprimir.setFont(new java.awt.Font("Arial", 0, 14));
cmdImprimir.setText("Imprimir");
cmdImprimir.setName("cmdLimpar"); // NOI18N
cmdImprimir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdImprimirActionPerformed(evt);
}
});
cmdLimpar.setFont(new java.awt.Font("Arial", 0, 14));
cmdLimpar.setText("Limpar");
cmdLimpar.setName("cmdLimpar"); // NOI18N
cmdLimpar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdLimparActionPerformed(evt);
}
});
cmdSair.setFont(new java.awt.Font("Arial", 0, 14));
cmdSair.setText("Sair");
cmdSair.setName("cmdLimpar"); // NOI18N
cmdSair.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdSairActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addComponent(jPanel1, 0, 577, Short.MAX_VALUE)
.addContainerGap(23, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(48, Short.MAX_VALUE)
.addComponent(cmdImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(77, 77, 77)
.addComponent(cmdLimpar, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(72, 72, 72)
.addComponent(cmdSair, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(44, 44, 44))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmdImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cmdLimpar, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cmdSair, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(31, Short.MAX_VALUE))
);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-638)/2, (screenSize.height-289)/2, 638, 289);
}// </editor-fold>
private void txtNrAIActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
txtNrTal.requestFocus();
}
private void txtNrTalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
pesquisaAI();
}
private void cmdImprimirActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
ImprimeFolhaRosto imprimir = new ImprimeFolhaRosto();
imprimir.ImprimirFolhaRosto(varIdNrAI.toString(), varIdNrTal.toString());
}
catch(Exception e)
{
Logger.getLogger(TelaFolhaRosto.class.getName()).log(Level.SEVERE, null, e);
}
}
private void cmdLimparActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
LimpaCampos();
inibeCampos();
txtNrAI.requestFocus();
}
private void cmdSairActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
TelaFolhaRosto.this.setVisible(false);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TelaFolhaRosto().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton cmdImprimir;
private javax.swing.JButton cmdLimpar;
private javax.swing.JButton cmdSair;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField txtAutuado;
public javax.swing.JFormattedTextField txtNrAI;
private javax.swing.JFormattedTextField txtNrTal;
// End of variables declaration
}[/code]
[code]
/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
import java.util.HashMap;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
/**
*
-
*/
public class ImprimeFolhaRosto {public void ImprimirFolhaRosto(String varIdNrAI, String varIdNrTal){
try{ HashMap<String, String> parameterMap = new HashMap<String, String>(); parameterMap.put("PAR_NRAI", varIdNrAI); parameterMap.put("PAR_NRTAL", varIdNrTal); String arquivo = System.getProperty("user.dir") + "/dist/FolhaRosto.jasper"; JasperPrint jp = JasperFillManager.fillReport(arquivo, parameterMap, BD.cnn); JasperViewer.viewReport(jp, false); } catch(JRException e) { e.printStackTrace(); }}
}[/code]
Dentro do NetBeans tudo funciona perfeitamente. Ao gerar o .Jar e instalar na máquina destinatária do sistema aí é que o problema apare: os relatórios não são carregados.
É necessário alterar o Manifest para que os relatórios .jasper funcionem com o .jar?