[RESOLVIDO] Relatórios pelo JasperSoft Studio (TIBCO)

<package telas;

import DAO.BuscaCodigoDAO;
import DAO.DAOException;
import java.io.File;
import java.util.List;
import java.util.logging.Level;
import javax.swing.JOptionPane;
import model.ModelReport;
import net.sf.jasperreports.engine.JRException;
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.view.JasperViewer;

public class telaImpressãoEtiquetas extends javax.swing.JInternalFrame {

public telaImpressãoEtiquetas() {
    initComponents();
    
    Campo2.setEditable(false);
    Campo3.setEditable(false);
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    jPanel1 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    Campo1 = new javax.swing.JTextField();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    Campo2 = new javax.swing.JTextField();
    jLabel5 = new javax.swing.JLabel();
    Campo3 = new javax.swing.JTextField();
    imprime1Btn = new javax.swing.JButton();
    imprime2Btn = new javax.swing.JButton();

    setClosable(true);
    setTitle("Impressão de Etiquetas");

    jLabel1.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
    jLabel1.setText("Código Atual:");

    jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
    jLabel2.setText("Imprimir apenas uma etiqueta");

    jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
    jLabel3.setText("Imprimir etiquetas em sequência");

    jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
    jLabel4.setText("Código de:");

    jLabel5.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
    jLabel5.setText("à");

    imprime1Btn.setText("Imprimir");
    imprime1Btn.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            imprime1BtnActionPerformed(evt);
        }
    });

    imprime2Btn.setText("Imprimir");

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Campo1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(imprime1Btn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(jLabel4)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(Campo2, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel5)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(Campo3, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(imprime2Btn)))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jLabel2)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1)
                .addComponent(Campo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(imprime1Btn))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jLabel3)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel4)
                .addComponent(Campo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel5)
                .addComponent(Campo3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(imprime2Btn))
            .addContainerGap(23, Short.MAX_VALUE))
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );

    pack();
}// </editor-fold>                        

private void imprime1BtnActionPerformed(java.awt.event.ActionEvent evt) {                                            
    
    File arquivo = new File("etiqueta.jasper");
    String caminho = arquivo.getAbsolutePath();
    try {
        BuscaCodigoDAO lista = new BuscaCodigoDAO();
        List<ModelReport> list;
        list = lista.busca(Integer.parseInt(Campo1.getText()));
        
        JasperReport relatorio;
        relatorio = JasperCompileManager.compileReport(caminho);
        JRBeanCollectionDataSource dados = new JRBeanCollectionDataSource(list,true);
        
        JasperPrint print = JasperFillManager.fillReport(relatorio, null, dados);
        JasperViewer view = new JasperViewer(print, false);
        view.setVisible(true);
        view.toFront();
        JOptionPane.showMessageDialog(null,"Impressão concluída!");
    } catch (JRException ex) {
        java.util.logging.Logger.getLogger(telaImpressãoEtiquetas.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DAOException ex) {
        java.util.logging.Logger.getLogger(telaImpressãoEtiquetas.class.getName()).log(Level.SEVERE, null, ex);
    } 
}                                           


// Variables declaration - do not modify                     
private javax.swing.JTextField Campo1;
private javax.swing.JTextField Campo2;
private javax.swing.JTextField Campo3;
private javax.swing.JButton imprime1Btn;
private javax.swing.JButton imprime2Btn;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
// End of variables declaration                   

}

quando uso o jrxml ele funciona normalmente apenas no netbeans…
Hoje primeira vez que usei o .jasper ele deu o seguinte erro:

net.sf.jasperreports.engine.JRException: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Byte inválido 1 da sequência UTF-8 do byte 1.
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:306)
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:285)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:274)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:219)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:194)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:185)
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:288)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:575)
at telas.telaImpressãoEtiquetas.imprime1BtnActionPerformed(telaImpressãoEtiquetas.java:145)
at telas.telaImpressãoEtiquetas.access$000(telaImpressãoEtiquetas.java:19)
at telas.telaImpressãoEtiquetas$1.actionPerformed(telaImpressãoEtiquetas.java:65)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Byte inválido 1 da sequência UTF-8 do byte 1.
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:701)
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:567)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1896)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.arrangeCapacity(XMLEntityScanner.java:1761)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipString(XMLEntityScanner.java:1799)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:156)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:805)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at org.apache.commons.digester.Digester.parse(Digester.java:1892)
at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:298)
… 46 more

Tá e com o jrxml qual erro que dá?

ele não me retorna um erro, quando executo pelo .jar ele simplesmente não me retorna nada,
sendo que quando executado pelo netbeans, estava funcionando normal

vai no CMD, aí digita:

java -jar oCaminhoDoSeuJar.jar

Lembrando que não pode ter espaço ou acentos especiais

ele me retorna um File Not Found Exception

Boa, ele não ta achando o arquivo, você não especificou nenhuma pasta, nenhum caminho pro arquivo, só colocou o nome dele lá, tenta especificar melhor onde ta o seu arquivo.

File arquivo = new File("etiqueta.jasper");

deu esse erro no cmd

C:\Users\Look\Desktop\sistemaLook\dist>java -jar sistemaLook.jar
ago 05, 2018 11:21:00 PM telas.telaImpressÒoEtiquetas imprime1BtnActionPerformed
GRAVE: null
net.sf.jasperreports.engine.JRException: Error compiling report java source files: C:\Users\Look\Desktop\sistemaLook\dist\Blank_A4_1533522060109_747617.java .
at net.sf.jasperreports.engine.design.JRJavacCompiler.compileClasses(JRJavacCompiler.java:105)
at net.sf.jasperreports.engine.design.JRAbstractClassCompiler.compileUnits(JRAbstractClassCompiler.java:74)
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:212)
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:357)
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:290)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:575)
at telas.telaImpressÒoEtiquetas.imprime1BtnActionPerformed(telaImpressÒoEtiquetas.java:145)
at telas.telaImpressÒoEtiquetas.access$000(telaImpressÒoEtiquetas.java:19)
at telas.telaImpressÒoEtiquetas$1.actionPerformed(telaImpressÒoEtiquetas.java:65)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.io.IOException: Cannot run program “javac”: CreateProcess error=2, O sistema nÒo pode encontrar o arquivo especificado
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at net.sf.jasperreports.engine.design.JRJavacCompiler.compileClasses(JRJavacCompiler.java:74)
… 44 more
Caused by: java.io.IOException: CreateProcess error=2, O sistema nÒo pode encontrar o arquivo especificado
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
… 48 more

deixei a linha do codigo assim:

<File arquivo = new File(“C:/Users/Look/Desktop/sistemaLook/src/img/etiqueta.jrxml”);>

depois de arrumar o caminho conforme a ultima postagem, adicionei uma biblioteca (jtd-compiler)
ai funcionou.

Obrigado pela ajuda amigo!

Opa, eu tive que dar uma saída aqui, desculpa a demora!! Que bom que funcionou!

sem problemas!
ainda consegui otimizar o relatório.

o único “ruim” da questão e que o arquivo não ira com o .jar ne?
pois ele vai buscar o relatório naquele endereço que passei

Mas dá pra por no .jar, faz assim, coloca o seu relatorio em alguma pasta do seu projeto e depois coloca assim:

JasperPrint jpPrint = JasperFillManager.fillReport(getClass().getResourceAsStream("/relatorio/seuRelatorio.jrxml"), new HashMap(), relatResul);

Nesse exemplo acima eu coloquei dentro da pasta “relatorio”

então, coloquei ele dessa forma
<JasperPrint jpPrint = JasperFillManager.fillReport(getClass().getResourceAsStream("/src/img/etiqueta.jrxml"), null, dados);>
ai ele retornou null pointer
e assim
<JasperPrint jpPrint = JasperFillManager.fillReport(getClass().getResourceAsStream("/img/etiqueta.jrxml"), null, dados);>
ele retornou error loading object from input stream

Vê se alguma dessas soluções te ajuda:

Error loading object from InputStream,
http://javafree.uol.com.br/topic-868415-IReport-Excecao-em-fillReport-JRException-Error-loading.html,
https://coderanch.com/t/62356/open-source/jasper-report-loading-stream,
JasperReports - Error loading object from InputStream RESOLVIDO.

Se src é a pasta onde estão seus fontes, então seu método tem que ser assim:

getClasss().getResourceAsStream("/img/etiqueta.jrxml")

O “/” no parâmetro do getResourceAsStream indica que é pra procurar a partir da raíz do classpath da aplicação.
A pasta src não faz parte do classpath

vou olhar, depois posto aqui os resultados
obrigado!

fiz desse modo conforme citado anteriormente, porém ele me retornou um erro…
não sei o motivo… será porque ele “não está dentro do projeto” ou algo assim?

Como não tá dentro do projeto?

Ele está dentro, porém usando o metodo que foi citado e que eu testei antes
ele tinha me dado o erro e eu achei que o motivo pudesse ser por não estar localizando a imagem dentro do pacote