2
Good afternoon Gentlemen!
I have a problem and none of the other posts could help me...
I was checking my TCC and I just came across the following problem: My executable. JAR cannot identify the folder where the reports created by iReport version 5.6.0 are located.
In my project, I have a folder br.integrado.Ports where I keep all of mine . Besides having already imported the iReport libraries to the project.
This is my code for "printing" the report:
public class RelatorioService {
private static final String FOLDER = "/br/integrado/reports";
public void gerarRelatorio(HashMap parametros, String nomeRelatorioJasper) throws JRException {
String caminhoRelatorio = this.getClass().getResource(FOLDER).getPath();
String caminhoArquivosJasper = caminhoRelatorio + File.separator + nomeRelatorioJasper + ".jasper";
JasperReport relatorioJasper = (JasperReport) JRLoader.loadObjectFromFile(caminhoArquivosJasper);
JasperPrint impressoraJasper = JasperFillManager.fillReport(relatorioJasper, parametros, ConexaoJDBC.getConexao());
JasperViewer jrv = new JasperViewer(impressoraJasper, false);
jrv.setVisible(true);
jrv.toFront();
}
}
In netbeans works perfectly, but in . jar it generates me the following Exception by CMD:
nov 25, 2018 2:04:00 PM br.integrado.view.RelListagemClienteView jButton1ActionPerformed
GRAVE: null net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: file:\C:\Users\willz\Documents\GitHub\TCC\StoreSoft\dist\StoreSoft.jar!\ en integrated Ports Listingclientesreport.Jasper at net.sf.jasperreports.engine.util.JRLoader.loadObject(Jrloader.java:114) at net.sf.jasperreports.engine.util.JRLoader.loadObject(Jrloader.java:103) at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromFile(Jrloader.java:94) at br.integrado.Reports.RelatorioService.gerarRelatorio(Reportaryservice.java:33) at br.integrado.view.RelListagemClienteView.printRelatory(Rellistagemclienteview.java:269) at br.integrado.view.RelListagemClienteView.jButton1ActionPerformed(Rellistagemclienteview.java:197) at br.integrado.view.RelListagemClienteView.access$300(Rellistagemclienteview.java:24) at br.integrado.view.Rellistagemclienteview$4.actionPerformed(Rellistagemclienteview.java:136) 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.Filenotfoundexception: file: C: Users Willz Documents Github TCC Storesoft dist Storesoft.jar! en integrated Ports Listingclientesreport.Jasper
Could someone help me?
Try
String caminhoRelatorio = RelatorioService.class.getResourceAsStream(FOLDER)
. Please let me know if it works.– StatelessDev
Good morning! I followed your instructions and in netbeans works perfectly, unfortunately the executable still has Nullpointer error. The following is the code: http://prntscr.com/ln5gyh
– Willian Rafael
This is the error generated in cmd next to the file path: http://prntscr.com/ln5hmi
– Willian Rafael
And this is the directory of my dist: http://prntscr.com/ln5i20
– Willian Rafael